Download

Is there a way to send ActionScript ExternalInterface.call directly to a GFxObject instead of the GFxMoviePlayer?

I have a GFxMoviePlayer that contains a very large number of GFxObjects. I want the Scaleform UIComponent to be able to call a function directly into the GFxObject instead of going through the GFxMoviePlayer, which then has to figure out which GFxObject to route the function call to. Is there any way to do that automatically?

Yes, you just need to use ActionScriptSetFunction(“YourAs3FunctionName”) from your OnViewLoaded() function in your GfxObject class.

The best way is to assign delegates. Example:

class MyGfxObject extends GfxObject;

function OnViewLoaded()
{
    //Assign delegates for the incoming actionscript calls
    SetSomeFunctionDelegate(SomeFunction);

    super.OnViewLoaded();
}

delegate SomeFunctionDelegate(String someParam);
function SetSomeFunctionDelegate(delegate< SomeFunctionDelegate> d) 
{ 
    ActionScriptSetFunction("YourAs3FunctionName"); 
}

function SomeFunction(String someParam)
{
     `log("AS3 called me with " $ someParam);
}

Then in your AS3 UIComponent, simply call this.YourAs3FunctionName(someParam:String) and when you call it, it will call SomeFunction() in your US GfxObject class.

You need to define your UIComponent class as dynamic, otherwise the compiler will complain about calling a function that it thinks doesn’t exist. Example:

public dynamic class YourAs3Class extends UIComponent{
...

Once I figured out how to do this, it made my frontend code much more cleaner. I also used to have a ginormous GFxMoviePlayer class and would route all calls through it. This allows you to keep logic isolated into the gfx objects that use it.

Note: Make sure you keep your classes cleaning up after themselves. If you assign a callback to US, and then destroy that object in US, if AS3 tries to call that resource it will instantly crash the entire engine.

1 Like

Thank you so much! Worked like a charm. I just had to be sure to include the “this.” before the function call. This is really going to clean up my code. Thanks again!

Awesome! Glad I could help. This setup is not very well documented. It allowed me to scale my frontend app massively while keeping things clean and manageable :slight_smile: