As3 Air for Desktop 在 HtmlLoader 上使用 ExternalInterface


import flash.html.HTMLLoader;
import flash.events.Event;
import flash.external.ExternalInterface;

var _htmlLoader: HTMLLoader=new HTMLLoader() ;
_htmlLoader.runtimeApplicationDomain = ApplicationDomain.currentDomain;
_htmlLoader.load(new URLRequest("http://knights-honor.com/index.php"));
_htmlLoader.addEventListener(Event.COMPLETE, onComplete);
function onComplete(ev: Event) {
_htmlLoader.width = stage.width;
_htmlLoader.height = stage.height;
this.addChild(_htmlLoader);
ExternalInterface.call("games()");//to call the games function from javascript wittin htmlloader
}

但是我收到此错误: 错误:错误 #2067:外部接口在此容器中不可用。外部接口需要 Internet Explorer ActiveX、Firefox、Mozilla 1.7.5 及更高版本,或其他支持 NPRuntime 的浏览器。

我做错了什么?

不能在AS3 主机和子HTMLLoader之间HTMLLoader使用ExternalInterface。 您可以将其与嵌入在 HTMLLoader 中加载的 HTML 内容中的子 SWF 一起使用。 但这里的情况并非如此。

你可以做的是访问HTMLLoader的javascriptwindow对象,以便在两者之间进行交互。

因此,在 AS3 代码中,将外部接口行替换为:

_htmlLoader.window.games();

假设 javascriptgames()方法在全局范围(窗口(中。

同样,可以在窗口对象上设置对 AS3 函数的引用:

function flashFunction():void {
trace("Flash Function Called");
}
_htmlLoader.window.flashFunction = flashFunction;

然后在您的 html 中:

<button onclick="flashFunction()">Run Flash Function</button>

相关内容

  • 没有找到相关文章

最新更新