在HtmlLoader上使用ExternalInterface的As3 Air for Desktop

时间:2017-07-19 12:04:54

标签: actionscript-3 flash air

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:此容器中的ExternalInterface不可用。 ExternalInterface需要Internet Explorer ActiveX,Firefox,Mozilla 1.7.5及更高版本,或其他支持NPRuntime的浏览器。

我做错了什么?

1 个答案:

答案 0 :(得分:0)

您无法在AS3主机与子ExternalInterface之间使用HTMLLoader HTMLLoader。您可以将其与嵌入在HTMLLoader中加载的HTML内容中的子SWF一起使用。但事实并非如此。

您可以执行的操作是访问HTMLLoader的javascript window对象,以便在两者之间进行互动。

因此,在AS3代码中,将ExternalInterface行替换为:

_htmlLoader.window.games();

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

以同样的方式,您可以在窗口对象上设置对AS3功能的引用:

function flashFunction():void {
    trace("Flash Function Called");
}

_htmlLoader.window.flashFunction = flashFunction;

然后在你的html:

<button onclick="flashFunction()">Run Flash Function</button>
相关问题