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

}

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 ?

Amir Rasti
  • 706
  • 7
  • 19
  • 1
    **ExternalInterface** is to communicate with environment, that is exactly **external** for the current Flash content: a web page that contains the Flash movie, an application that runs Flash content, and so on. **HTMLLoader** is an **internal** object, not the external environment. – Organis Jul 19 '17 at 12:21
  • 1
    it is used in this case too as mentioned in this post https://stackoverflow.com/questions/35956597/how-do-i-communicate-between-js-and-as3-in-an-air-android-application commented by  Dodger Thud and referred to http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/external/ExternalInterface.html but adobe has blocked irans ips then I cant access the documentation – Amir Rasti Jul 19 '17 at 17:31
  • 1
    In Adobe AIR, the ExternalInterface class can be used to communicate between JavaScript in an HTML page loaded in the HTMLLoader control and ActionScript in SWF content embedded in that HTML page. – Amir Rasti Jul 19 '17 at 17:33
  • 1
    as I set the title its an air for desktop project then its loading a html page inside the swf – Amir Rasti Jul 19 '17 at 18:17

1 Answers1

1

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>
BadFeelingAboutThis
  • 14,445
  • 2
  • 33
  • 40