2017-07-19 123 views
2
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 

} 

使用ExternalInterface的,但我得到這個錯誤: 錯誤:錯誤#2067:ExternalInterface的是不是在這個容器中使用。 ExternalInterface需要Internet Explorer ActiveX,Firefox,Mozilla 1.7.5或更高版本,或其他支持NPRuntime的瀏覽器。AS3空氣桌面上的HTMLLoader

我做錯了什麼?

+1

** **的ExternalInterface與溝通環境,對於當前的Flash內容,這完全是** external **:包含Flash影片的網頁,運行Flash內容的應用程序等等。 ** HTMLLoader **是一個**內部**對象,而不是外部環境。 – Organis

+1

它在這種情況下也使用,如本文所述https://stackoverflow.com/questions/35956597/how-do-i-communicate-between-js-and-as3-in-an-air-android-application Dodger Thud評論並提到http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/external/ExternalInterface.html,但Adobe已封鎖irans ips,然後我無法訪問文檔 –

+1

在Adobe AIR ,可以使用ExternalInterface類在HTMLLoader控件中加載的HTML頁面中的JavaScript與HTML頁面中嵌入的SWF內容中的ActionScript之間進行通信。 –

回答

0

您不能在AS3主機和子女HTMLLoader之間使用ExternalInterfaceHTMLLoader。您可以將其與嵌入在HTMLLoader中加載的HTML內容中的子SWF一起使用。儘管如此,情況並非如此。

你能做什麼,就是訪問HTMLLoader的javascript window對象來進行二者之間的交互。

_htmlLoader.window.games(); 

假設的JavaScript games()方法是在全球範圍內(窗口):

所以在你的AS3代碼,代之以ExternalInterface的線。

以同樣的方式,你可以設置窗口對象的引用的AS3功能:

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

_htmlLoader.window.flashFunction = flashFunction; 

然後在您的html:

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