【发布时间】:2009-01-15 20:57:17
【问题描述】:
所以我有一个应用程序沙箱 HTMLLoader 对象,我在 AIR 中创建它,并且只想从 JavaScript 调用 ActionScript 方法。在 Flash 中,这是通过我们值得信赖的 ExternalInterface.addCallback() 函数完成的。但是在 AIR 中,情况就大不相同了,我似乎无法让它发挥作用。
这是我的项目的简化概述:
My AIR (ActionScript) 主目录:
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);
}
}
这就是我创建 HTMLLoader 对象的方式:
{
_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);
}
最后,这是我的 AirRoot.html 文件中的 JavaScript sn-p,它试图调用在我的 Main 中声明的公共方法 as3Function()类:
Exposed.testAs3 = function()
{
air.trace("Exposed.testAs3 called"); /* This works fine. */
air.trace("runtimeVersion:"); /* This works fine. */
air.trace(air.NativeApplication.nativeApplication.runtimeVersion); /* This works fine. */
air.trace("seeing if I can get to AS3 params..."); /* This works fine. */
/* This doesn't work - get the following error: TypeError: Value undefined does not allow function calls. */
air.NativeApplication.nativeApplication.as3Function();
}
我错过了什么?
【问题讨论】:
标签: actionscript air