代码之家  ›  专栏  ›  技术社区  ›  Amir Rasti

在HtmlLoader上使用ExternalInterface的As3 Air for Desktop

  •  2
  • Amir Rasti  · 技术社区  · 7 年前
    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
    
    }
    

    我做错了什么?

    1 回复  |  直到 7 年前
        1
  •  1
  •   BadFeelingAboutThis    7 年前

    您不能使用 ExternalInterface 具有 HTMLLoader AS3主机和儿童之间 HTMLLoader 。您可以将其与嵌入在HTMLLoader中加载的HTML内容中的子SWF一起使用。然而,这里的情况并非如此。

    HTMLLoader 的javascript window 对象之间进行交互。

    _htmlLoader.window.games();
    

    假设javascript games() 方法在全局范围(窗口)中。

    同样,可以在窗口对象上设置对AS3函数的引用:

    function flashFunction():void {
        trace("Flash Function Called");
    }
    
    _htmlLoader.window.flashFunction = flashFunction;
    

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