Search Unity

Get info from Unity into Flash

Discussion in 'Flash' started by Superflat, Apr 14, 2012.

  1. Superflat

    Superflat

    Joined:
    Mar 19, 2009
    Posts:
    354
    I've created a FlashProxy.cs file with some functions:

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. [NotConverted]
    5. [NotRenamed]
    6. public class FlashProxy : MonoBehaviour
    7. {
    8.     public static void setHost(object o)
    9.     {
    10.        
    11.     }
    12.    
    13.     public static void UpdateTime(object o)
    14.     {
    15.  
    16.     }
    17. }
    18.  
    And in an ActionScript directory in my unity project i put the appropriate .as file.

    Code (csharp):
    1. package
    2. {
    3.     import flash.display.MovieClip;
    4.     import flash.display.Stage;
    5.  
    6.     public class FlashProxy
    7.     {
    8.         static var _stage:Stage;
    9.         static var _mc:MovieClip;
    10.         public static function setHost(o:Object):void
    11.         {
    12.             _mc = o.host as MovieClip;
    13.             _stage = _mc.stage;
    14.         }
    15.  
    16.         public static function UpdateTime(n:Number):void
    17.         {
    18.             _mc.log(n);
    19.         }
    20.     }
    21. }
    However, when i run my flash project that loads up the unity.swf and i call the UpdateTime function i get the following error:

    Code (csharp):
    1. TypeError: Error #1009: Cannot access a property or method of a null object reference.
    2.     at FlashProxy$/UpdateTime()[/Users/Kevin/Documents/Work/TKD/Assets/ActionScript/FlashProxy.as:18]
    3.     at global::Controller/Controller_GetAnimationTime()[/Users/Kevin/Documents/Work/TKD/Temp/StagingArea/Data/ConvertedDotNetCode/global/Controller.as:38]
    4.     at com.unity::UnityNative$/Ext_Flash_InvokeMethodOnObject()
    5.     at com.unity::UnityNative$/_ZN13MonoBehaviour30InvokeMethodOrCoroutineCheckedEP15ScriptingMethodPFP15ScriptingObjectPvPP18ScriptingExceptionES3_()
    6.     at com.unity::UnityNative$/_Z15SendMonoMessageRN5Unity10GameObjectEPKcP15ScriptingObject()
    7.     at com.unity::UnityNative$/NativeExt_SendMessage()
    8.     at com.unity::UnityContentInternal/sendMessage()
    9.     at com.unity::UnityContent/sendMessage()
    10.     at nl.superflat.screenmanager.screen::PatternsScreen/updateTime()[/Users/Kevin/Documents/Work/TKD Flash/src/nl/superflat/screenmanager/screen/PatternsScreen.as:79]
    11.  
    12. (Filename:  Line: 0)
    It's still referring to the FlashProxy.as file that i had in my unity project. Have i set all this up incorrectly?
     
    Last edited: Apr 22, 2012
  2. Superflat

    Superflat

    Joined:
    Mar 19, 2009
    Posts:
    354
  3. cannon

    cannon

    Joined:
    Jun 5, 2009
    Posts:
    751
    Do you have another FlashProxy defined aside from the one in Unity?

    From the error, it looks like setHost was not called with a valid movieclip.
     
  4. RalphH

    RalphH

    Administrator

    Joined:
    Dec 22, 2011
    Posts:
    592
    The error indicates that the variable _mc is not set.
     
  5. Superflat

    Superflat

    Joined:
    Mar 19, 2009
    Posts:
    354
    Attached is a zip file with my AS3 and C# code. Should give you a better idea of what might be going wrong.

    Is it required to have an actual FlashProxy.as class present in the as3 project? I made adjustments but the problems still occur.
     

    Attached Files:

  6. RalphH

    RalphH

    Administrator

    Joined:
    Dec 22, 2011
    Posts:
    592
    Is the error you are dealing with the same as your initial post ?

    If so in this function of flashproxy;
    public static function UpdateTime(n:Number):void
    {
    _mc.log(n);
    }

    Check that _mc is not null first, then check where it's set that it's actually set to a non null object.
     
  7. Superflat

    Superflat

    Joined:
    Mar 19, 2009
    Posts:
    354
    Hi Ralph,

    I found that my host wasn't being set because the functions from IUnityContentHost aren't being called. Right now i'm loading the swf using a normal loader and then casting it as UnityContent because SetSize wasn't working.

    Has this been fixed yet?

    [EDIT] I got it all working when i use the regular UnityContentLoader except the SetSize. If i do it the other way around with a normal Loader it all works as well except that I have to wait with setting the the contenthost because the unity content isn't ready when it's done loading.

    Anyway to set the size after it's all loaded using the UnityContentLoader? i tried setting the size on the .content.
     
    Last edited: Apr 29, 2012