2012-12-10 69 views
1

我有一個嵌入了YouTube視頻的Flash橫幅廣告。當用戶按下按鈕時,橫幅將轉到特定的框架並播放視頻。我需要做的是在視頻完成後,轉發到另一幀。帶動作腳本3的YouTube API

我現在用在YouTube視頻拉AS3低於:

stop(); 

var player:Object; 

Security.allowDomain("www.youtube.com"); 

var vidctn:Loader = new Loader(); 
vidctn.load(new URLRequest("http://www.youtube.com/apiplayer?version=3")); 
vidctn.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit); 

function onLoaderInit(e:Event):void{ 
addChild(vidctn); 
player = vidctn.content; 
player.addEventListener("onReady", onPlayerReady); 
} 

function onPlayerReady(e:Event):void{ 
player.destroy(); 
addChildAt(vidctn,0); 
player.setSize(304,173); 
player.x = 0; 
player.y = 40; 
player.mute(); 
player.loadVideoById("Dzz6lUsF19g",0,"large"); 
} 

我想我需要一個事件偵聽,可能Event.COMPLETE,但我似乎無法拿出一個。

回答

0

這些都是YouTube的API的狀態(你只需要YT_ENDED,但它是好的,有所有):

 public static var YT_UNSTARTED:int = -1; 
     public static var YT_ENDED:int = 0; 
     public static var YT_PLAYING:int = 1; 
     public static var YT_PAUSED:int = 2; 
     public static var YT_BUFFERING:int = 3; 
     public static var YT_CUED:int = 5; 

添加一個偵聽器:

 vidctn.contentLoaderInfo.addEventListener("onStateChange", onPlayerStateChange); 

,這裏是功能:

 protected function onPlayerStateChange(event:Event):void { 
      trace("youtubePlayer: player state:", Object(event).data); 
      if(Object(event).data==YT_ENDED) { 
        //here you can do your stuff 
      } 
     }