As3 Air for Desktop 在 HtmlLoader 上使用 ExternalInterface
As3 Air for Desktop using ExternalInterface on HtmlLoader
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 的浏览器。
我做错了什么?
您不能在 AS3 主机和子 HTMLLoader
之间使用 ExternalInterface
和 HTMLLoader
。您可以将它与嵌入在 HTML 内容中的子 SWF 一起使用,该内容由 HTMLLoader 加载。不过这里不是这种情况。
您可以做的是访问 HTMLLoader
的 javascript window
对象以在两者之间进行交互。
因此,在您的 AS3 代码中,将 ExternalInterface 行替换为:
_htmlLoader.window.games();
假设 javascript games()
方法在全局范围内 (window)。
以同样的方式,您可以在 window 对象上设置对 AS3 函数的引用:
function flashFunction():void {
trace("Flash Function Called");
}
_htmlLoader.window.flashFunction = flashFunction;
然后在你的 html:
<button onclick="flashFunction()">Run Flash Function</button>
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 的浏览器。
我做错了什么?
您不能在 AS3 主机和子 HTMLLoader
之间使用 ExternalInterface
和 HTMLLoader
。您可以将它与嵌入在 HTML 内容中的子 SWF 一起使用,该内容由 HTMLLoader 加载。不过这里不是这种情况。
您可以做的是访问 HTMLLoader
的 javascript window
对象以在两者之间进行交互。
因此,在您的 AS3 代码中,将 ExternalInterface 行替换为:
_htmlLoader.window.games();
假设 javascript games()
方法在全局范围内 (window)。
以同样的方式,您可以在 window 对象上设置对 AS3 函数的引用:
function flashFunction():void {
trace("Flash Function Called");
}
_htmlLoader.window.flashFunction = flashFunction;
然后在你的 html:
<button onclick="flashFunction()">Run Flash Function</button>