简体   繁体   中英

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

}

but I get this error : Error: Error #2067: The ExternalInterface is not available in this container. ExternalInterface requires Internet Explorer ActiveX, Firefox, Mozilla 1.7.5 and greater, or other browsers that support NPRuntime.

what am I doing wrong ?

You cannot use ExternalInterface with HTMLLoader between the AS3 host and a child HTMLLoader . You can use it with a child SWF that is embedded in HTML content loaded in an HTMLLoader. That is not the case here though.

What you can do, is access the HTMLLoader 's javascript window object to interact between the two.

So in your AS3 code, replace the ExternalInterface line with:

_htmlLoader.window.games();

Assuming the javascript games() method is in the global scope (window).

In the same way, you can set a reference to an AS3 function on the window object:

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

_htmlLoader.window.flashFunction = flashFunction;

Then in your html:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM