0

我在我的网站上使用 youtube 的 AS3 flash 播放器。我可以让它在视频完成后自动转发到特定页面吗?我该怎么做?

4

1 回答 1

0

即使在使用 AS3 播放器时,您仍然可以注册 javascript 处理程序;当您加载播放器时,请确保您追加

enablejsapi=1

作为 URL 的参数。一旦您为 AS3 播放器注册了 javascript 处理程序,您就可以添加一个 javascript 监听器到播放器状态更改(特别是 ENDED 状态):

function onytplayerStateChange(newState) {
   if (newState===YT.PlayerState.ENDED) {
      // do redirect here
   }
}

编辑

准备好 javascript 侦听器后,您可以设置一个 actionscript 侦听器,该侦听器将在任何状态更改时调用此 javascript 函数。像这样的东西,也许(未经测试):

// 'loader' below is the youtube actionscript loader object

function onLoaderInit(event:Event):void {
    addChild(loader);
    loader.content.addEventListener("onStateChange", onPlayerStateChange);
}

function onPlayerStateChange(event:Event):void {
    // Event.data contains the event parameter, which is the new player state
// make sure ExternalInterface is imported
    ExternalInterface.call("onytplayerStateChange()", Object(event).data); // calls the javascript function

}
于 2012-11-08T07:14:16.377 回答