So, I have an Application Sandbox HTML desktop object that I create in AIR and just want to call ActionScript methods from JavaScript . In Flash, this is achieved using our robust ExternalInterface.addCallback () function . However, in AIR, everything is completely different, and I just can not get it to work.
Here is a simplified overview of my project:
My AIR (ActionScript) main:
public class Main extends Sprite {
public var _as3Var:String = "testing";
public function as3Function():void
{
trace("as3Function called from Javascript");
}
public function Main() {
NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, onInvoke);
}
protected function onInvoke(e:InvokeEvent):void {
NativeApplication.nativeApplication.removeEventListener(InvokeEvent.INVOKE, onInvoke );
var app = new App();
addChild(app);
app.init(new ExternalContainer(), e.currentDirectory, e.arguments);
}
}
And this is how I create my HTMLLoader object:
{
_html = new HTMLLoader();
_html.useCache = false;
_html.runtimeApplicationDomain = ApplicationDomain.currentDomain;
_html.load(new URLRequest("sandbox/AirRoot.html"));
_html.width = 800;
_html.height = 600;
App.ref.addChild(_html);
}
And finally, here is my JavaScript snippet in my AirRoot.html file that is trying to call the as3Function () public method declared in my main class:
Exposed.testAs3 = function()
{
air.trace("Exposed.testAs3 called");
air.trace("runtimeVersion:");
air.trace(air.NativeApplication.nativeApplication.runtimeVersion);
air.trace("seeing if I can get to AS3 params...");
air.NativeApplication.nativeApplication.as3Function();
}
?