dojox.embed.flash上​​的dojo eventListener

时间:2010-12-16 17:59:31

标签: javascript flash dojo

如何在flash嵌入中添加eventlistener? (new dojox.embed.Flash)我尝试了dojo.connectaddEventListener,但都没有工作

代码段:

this.player = new dojox.embed.Flash({
 path: 'http://player.soundcloud.com/player.swf?url='+track.stream_url+'&enable_api=true&player_type=engine&object_id='+this.playerId,
 width: 5,
 height: 5,
 id: this.playerId,
 name: this.playerId,
 minimumVersion: 9,
 allowScriptAccess: 'always'
}, dojo.byId('soundcloud_flash'));

这些都不起作用:

dojo.connect(this.player.movie, 'onMediaBuffering', function(id, data) { console.log('dfg'); obj.progress(data.percent); });
dojo.connect(this.player.movie, 'onMediaBuffering', dojo.hitch(this, function(id, data){ console.log('ergh'); this.progress(data.percent);}));
dojo.connect(dojo.query(this.player.movie)[0], 'onMediaBuffering', function(id, data) { console.log('yu'); obj.progress(data.percent); });
dojo.connect(dojo.query(this.player.movie)[0], 'onMediaBuffering', dojo.hitch(this, function(id, data){ console.log('er'); this.progress(data.percent);}));
dojo.connect(this.player, 'onMediaBuffering', dojo.hitch(this, function(id, data){ console.log('ubg'); this.progress(data.percent);}));
dojo.connect(dojo.byId(this.player), 'onMediaBuffering', dojo.hitch(this, function(id, data){ console.log('asd'); this.progress(data.percent);}));
dojo.connect(dojo.query(this.player), 'onMediaBuffering', dojo.hitch(this, function(id, data){ console.log('asd'); this.progress(data.percent);}));
dojo.connect(dojo.query(this.player), 'onMediaBuffering', function(id, data){ console.log('hj'); this.progress(data.percent);});

此活动来自Sound Cloud付款人:https://github.com/soundcloud/Widget-JS-API/wiki

2 个答案:

答案 0 :(得分:1)

dojox.embed.Flash是一种嵌入Flash影片的简单机制,它还有一个代理方法,可以更轻松地通过ExternalInterface从JS对象调用ActionScript方法。我不认为它支持双向通信或支持事件,但您可以使用Flash API或执行调用来设置自己的回调。

dojo.connect仅适用于JavaScript函数之间的连接,并且不会镜像到ActionScript方法。请注意,onReady和onLoad Javascript事件在播放器对象上可用,您可以连接到这些事件。

编辑:仔细观察这个库,我猜onMediaBuffer是一个由Flash电影调用的Javascript方法,但是它设置为一个名为soundplayer的全局Javascript变量!更糟糕的是,他们为一些工具箱事件系统设置了一次性,复制了模式。

您可以尝试这样的事情:

dojo.connect(window.soundplayer, "onMediaBuffer", function(flashId, data){ ... });

答案 1 :(得分:1)

Peller指出我正确的方向,它是窗口上的全局功能:

 var soundcloud = window.soundcloud = {
    onMediaBuffering: function() {
        console.log('asdasdasd');
    }
}