代码之家  ›  专栏  ›  技术社区  ›  adamJLev

Flash外部接口和函数回调问题

  •  0
  • adamJLev  · 技术社区  · 14 年前

    <audio> 标签。

    getElementById('flashAudioPlayer').addEventListener('timeupdate', function() {
      // Do stuff
    });
    

    Flash控件是否支持这种类型的回调传递?它宁愿调用传入的函数对象,而不是静态的'ExternalInterface'调用,如上面的示例所示。

    谢谢!

    2 回复  |  直到 14 年前
        1
  •  2
  •   Juan Pablo Califano    14 年前

    也许从Actionscript方面使用JS eval是可行的,但是我认为有一个替代方法。

    大致如下:

    var proxyDispatcher = new ProxyDispatcher();
    var app = getYourSwf("myswf");
    // tell your app to call the dispatch method in the proxyDispatcher object everytime theres a timeupdate
    //  dispatch will receive the name of the event back, plus the "payload" data (that's up to you to define)
    app.registerCallback('proxyDispatcher.dispatch','timeupdate');
    // now, add "clients" here
    // the idea is that proxyDispatcher registers JS functions to be called when its dispatch method is called
    // so, when dispatch is called with 'timeupdate' as the event type, call all listeners for 'timeupdate'...
    proxyDispatcher.addEventListener('timeupdate',function() {
    
    });
    

    作为

    var _map:Object = {};
    
    private function handleRegisterCallback(jsCallback:String,eventName:String):void {
        _map[eventName] = jsCallback;
    }
    
        // when there's a timeupdate, check if you have a registered listener for it; if so, call it
    private function dispatchTimeupdate():void {
        if(_map['timeupdate']) {
            // call the registered function, pass the event name and any data you need
            ExternalInterface.call(_map['timeupdate'],'timeupdate','your data here');
        }
    }
    

    希望这有意义!

        2
  •  0
  •   Tyler Egeto    14 年前

    您可以将它们作为Flash变量或使用ExternalInterface传入。