Hello,
I managed to make the example project to run (the one in the spaceship), and now I'm trying to make scaleform work in my own project. My flash content is displayed in my game when I run it from unity Editor, and respond to mouse interaction, but Unity does not receive the ExternalInterface.call("OnRegisterSWFCallback", this), so I have no communication between my flash and unity.
public class Main extends MovieClip { public var testTxt:TextField; public var testBtn:MovieClip; public function Main() { testTxt.text = "Main"; stage.scaleMode = StageScaleMode.SHOW_ALL; addEventListener(Event.ADDED_TO_STAGE, configUI); testBtn.addEventListener(MouseEvent.CLICK, onBtnClick); } public function configUI(e:Event):void { removeEventListener(Event.ADDED_TO_STAGE, configUI); testTxt.text = "OnRegisterSWFCallback"; ExternalInterface.call("OnRegisterSWFCallback", this); } private function onBtnClick(event:MouseEvent):void { testTxt.text = "OnBtnUnity"; ExternalInterface.call("OnBtnUnity"); } }
Thanks to the testTxt, I know that it goes throught there.
And on the unity side :
public class MyFlash : Movie { protected Value theMovie = null; private CameraScaleform parent = null; public MyFlash(CameraScaleform parent, SFManager sfmgr, SFMovieCreationParams cp) : base(sfmgr, cp) { this.parent = parent; SFMgr = sfmgr; this.SetFocus(true); } public void OnRegisterSWFCallback(Value movieRef) { theMovie = movieRef; GameObject monitor_screen = GameObject.Find("monitor_screen"); monitor_screen.GetComponent<MyRTT>().enabled = true; } public void OnBtnUnity() { Value flashText = theMovie.GetMember("testTxt"); String textValue = (String) flashText.GetMember("text"); flashText.SetMember("text", textValue+"3"); } }
The code goes throught the MyFlash constructor, but not in the other functions.
I saw some old posts talking about adding Extensions.enabled = true in the flash, I try adding it to the beginning of my Main() function but it didn't change anything.
What is supposed to trigger the connection between the swf and unity ?
I don't understand what I'm doing different from the example project, does anybody has an idea ?
Unity version : 4.3.4f1 Pro
Scaleform licence : evaluation
OS : Windows 7 x64
Platform : PC
I also attached my unity editor log.
Solved! Go to Solution.
Solved by adam.petrone. Go to Solution.
You be should look the MyCamera.cs
ForExample:
SFMovieCreationParams creationParams = CreateMovieCreationParams("main_layout.swf");
SF_Main_Layout = new main_layout(this, SFMgr, creationParams);
The point is second line,
because i create a swf with "main_layout" calss,
scaleform will to find the class name "main_layout" in .as and library's MovieClip to add stage.
if you want to instance a MovieClip, is need to set as name in library,too. no conflict.
Hello,
Are you positive your code's configUI() is being called? Add in a trace statement to double-check.
Short of that, try adding an ExternalInterface.call("OnRegisterSWFCallback", this) on the timeline of the first frame of the stage -- that should allow you to quickly verify if Unity is receiving the message while resting assured your code is being called.
I don't understand, in MyCamera.cs main_layout.swf is the name of the swf, not the name of the AS linkage. And if it was the problem, my flash content would even not display in my unity game, no ? If I look at the scaleform example, there is no AS linkage, everything is on the main scene, except for fonts and some buttons that use specific classes, but nowhere there is a "main_menu" AS linkage :
http://www.dranem.net/upload/main_menu_flash_scene.jpg
Just for a comparaison, here is my scene :
http://www.dranem.net/upload/gui_flash_scene.jpg
So no I don't have AS linkage, but why would I need it ? (I still tried, to be sure, but that didn't change anything)
adam.petrone : Yes, it goes throught configUI(),
testTxt.text = "OnRegisterSWFCallback";
That part change the textfield text of my scene, and when I'm launching my game in the unity editor, I see my flash content with my textfield modified. By the way I tried using trace() call in the AS, checking "permit debugging" in publish setting of flash, but nothing gets displayed in the unity log, I guess I really have no communication at all between my flash content and unity...
Hi Dr4nem,
Please ensure that your Camera's update is calling base.Update().
A little more detail...
In Assets/Plugins/SF/SFManager.cs
Around line 731 (in the latest release), you should see a commented out "ExternalInterface arrived" line.
Uncomment this and re-run. You should at least see this message when these arrived at the Unity side. This is invoked by SFManager.ProcessCommands.
SFManager.ProcessCommands is called by SFCamera.Update. If your derived SFCamera isn't calling base.Update(), these will never get sent, but your movie should play (and respond to other input) accordingly. The input is event-based.
Thanks,
Adam
Oh man, that was it, base.Update() call missing...
I deleted too much of the MyCamera.cs... Thank you very much !