Announcements
The Scaleform forum is now read-only. Please head to the Gamedev site for product support.
Scaleform Forum (Read Only)
Scaleform enables developers to leverage the power of the Adobe® Flash® tool set to create powerful user interface environments for video games.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

AS3 to C# and back again HELP!!!!

4 REPLIES 4
Reply
Message 1 of 5
220573
534 Views, 4 Replies

AS3 to C# and back again HELP!!!!

Hello,

 

I have tried to do a tutorial that was posted on Youtube due to the fact that there are no step by step tutorials for Unity/Scaleform. Of course it doesnt work the way it was advertised and now after losing hours of my life that i wont get back i turn to the greater community for help. I have the unity package but cannot attach it to this message so below please find the relevant scripts. Please Help.

 

Action Script 3 Class

 

package 
{
 import flash.display.SimpleButton;
 import flash.display.Sprite;
 import flash.display.MovieClip;
 import flash.events.MouseEvent;
 import flash.external.ExternalInterface
 import flash.text.TextField;
 
 public class Main extends Sprite
 {
  public var txtInput: TextField;
  public var txtDisplay: TextField;
  public var btn1:SimpleButton;
  public var btn2:SimpleButton;
  
  public function Main()
  {
   stage.scaleMode = "showAll";
   btn1.addEventListener (MouseEvent.CLICK, onBtn1);
   btn2.addEventListener (MouseEvent.CLICK, onBtn2);
  }
  
  public function onBtn1(e:MouseEvent):void
  {
   trace("onBtn1 button click");
   ExternalInterface.call("onBtn1Unity", txtInput.text);
  }
  
  private function onBtn2(e:MouseEvent):void
  {
   ExternalInterface.call('onBtn2Unity', txtInput.text);
  }
  
  public function onReceivedFromUnity (txt:String):void
  {
   txtDisplay.text = "hello";
  }
 }
}

 

Flash Camera C# attached to the Camera in Unity

 

using UnityEngine;
using System.Runtime.InteropServices;
using System;
using System.IO;
using System.Text;
using System.Collections;
using Scaleform;
public class FlashCamera : SFCamera {

 public MyFlash ttFlash = null;

 new public  IEnumerator Start()
 {
  // The eval key must be set before any Scaleform related classes are loaded, other Scaleform Initialization will not
  // take place.
  #if (UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_EDITOR) && !UNITY_WP8
  //SF_SetKey ("");
  #elif UNITY_IPHONE
  SF_SetKey("");
  #elif UNITY_ANDROID
  SF_SetKey("");
  #elif UNITY_WP8
  sf_setKey("");
  #endif
  //For GL based platforms - Sets a number to use for Unity specific texture management.  Adjust this number if
  //you start to experience black and/or mssing textures.
  #if UNITY_WP8
  sf_setTextureCount(500);
  #else
  //SF_SetTextureCount(500);
  #endif

  InitParams.TheASVersion = SFInitParams.ASVersion.Both;
  return base.Start ();
 }
 new public void Update()
 {
  CreateMyFlash();
  base.Update();
 }
 private void CreateMyFlash()
 {
  if (ttFlash == null)
  {
   ttFlash = Util.CreateSwf<MyFlash>("JokersFlash.swf", false);
  }
 }
}

 

MyFlash C# the other script in Unity

 

using System;
using System.Collections;
using UnityEngine;
using Scaleform;

public class MyFlash : Movie
{
 protected Value theMovie = null;
 public FlashCamera parent = null;
 
 public MyFlash(FlashCamera parent, SFManager sfmgr, SFMovieCreationParams cp):
  base(sfmgr, cp)
 {
  this.parent = parent;
  SFMgr = sfmgr;
  this.SetFocus(true);
 }

 public void OnRegisterSWFCallback (Value movieRef)
 {
  theMovie = movieRef;
 }

 public void onBtn1Unity (String txt)
 {
  Value flashText = theMovie.GetMember ("txtDisplay");
  flashText.SetMember ("text", txt);
 }
 public void OnBtn2Unity (String txt)
 {
  theMovie.Invoke ("onReceivedFromUnity", txt);
 }
}

 

 

 

4 REPLIES 4
Message 2 of 5
Doobyman
in reply to: 220573

Have you debugged anything? I notice some errors in your code but I don't know if they will change anything:

In AS3, ExternalInterface.call('onBtn2Unity', txtInput.text); should have double quotes instead of single (at least in my experience).

Also in your onBtn1Unity, try flashText.SetText( txt ) instead.

OnBtn2Unity function has large O instead of small o.
Message 3 of 5
andrew_widdis
in reply to: Doobyman

Thanks for the ideas. No change!

 

When i click on the buttons,

In unity console i get

 

"NullReferenceException: Object reference not set to an instance of an object"

 

On both buttons

Message 4 of 5

Hi Andrew, did you solve your problem?

Message 5 of 5
zedaidai
in reply to: 220573

Hi,

It seems you're not calling the C# function OnRegisterSWFCallback.
In as3 there should be an external interface call to this function .
It will initialise theMovie variable which is used in onBtn1Unity and onBtn2Unity

in the Main.as constructor add :
ExternalInterface.call("OnRegisterSWFCallback", this);

 

Hope this helps

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report