【问题标题】:As3 Air for Desktop using ExternalInterface on HtmlLoaderAs3 Air for Desktop 在 HtmlLoader 上使用 ExternalInterface
【发布时间】:2017-07-19 12:04:53
【问题描述】:
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 的浏览器。

我做错了什么?

【问题讨论】:

  • ExternalInterface是与环境通信的,也就是当前Flash内容的external:一个包含Flash电影的网页,一个应用程序运行 Flash 内容等。 HTMLLoader 是一个 internal 对象,而不是外部环境。
  • 在这种情况下也使用了它,正如本文中提到的 stackoverflow.com/questions/35956597/… Dodger Thud 评论并提到了 help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/… 但 adobe 已阻止伊朗 ips 然后我无法访问文档
  • 在 Adob​​e AIR 中,ExternalInterface 类可用于在 HTMLLoader 控件中加载的 HTML 页面中的 JavaScript 与该 HTML 页面中嵌入的 SWF 内容中的 ActionScript 之间进行通信。
  • 当我将标题设置为桌面项目时,它会在 swf 中加载一个 html 页面

标签: actionscript-3 flash air


【解决方案1】:

您不能在 AS3 主机和子 HTMLLoader 之间使用 ExternalInterfaceHTMLLoader。您可以将它与嵌入在 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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多