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: 

Unity not receiving ExternalInterface.call from flash

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
Dr4nem
851 Views, 8 Replies

Unity not receiving ExternalInterface.call from flash

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.

 

8 REPLIES 8
Message 2 of 9
wesleyhuang
in reply to: Dr4nem

Maybe is your flash's AS Name not Set the same name

Message 3 of 9
wesleyhuang
in reply to: wesleyhuang

name.png

Message 4 of 9
Dr4nem
in reply to: wesleyhuang

Thank you for your answer, but I just have a textfield and a button set directly on the root scene, each of them has an instance name. Why would I need to give them an export name in the library ? It's only useful if I want to instantiate them at runtime no ?
Message 5 of 9
wesleyhuang
in reply to: Dr4nem

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.

 

Message 6 of 9
adam.petrone
in reply to: wesleyhuang

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.

Message 7 of 9
Dr4nem
in reply to: adam.petrone

wesleyhuang :

 

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...

 

 

Message 8 of 9
adam.petrone
in reply to: Dr4nem

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

Message 9 of 9
Dr4nem
in reply to: adam.petrone

Oh man, that was it, base.Update() call missing...

 

I deleted too much of the MyCamera.cs... Thank you very much !

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

Post to forums  

Autodesk Design & Make Report