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);
}
}
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
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.