2013-01-16 88 views
0

我已經將YouTube視頻嵌入到不同頁面的不同幀的Flash文件中,基本上,當我點擊顯示我的視頻的頁面時,YouTube視頻仍然在屏幕上,並且仍在播放聲音。我只想在一個畫面上顯示視頻,當我切換幀時聲音停止。這裏是我的代碼:Flash Youtube嵌入問題

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

var player : Object; 
var mute : Boolean = false; 

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

playButton.addEventListener(MouseEvent.CLICK, playVideo); 
pauseButton.addEventListener(MouseEvent.CLICK, pauseVideo); 
muteButton.addEventListener(MouseEvent.CLICK, muteVideo); 

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

function onPlayerReady(event:Event):void { 
    player = loader.content; 
    player.setSize(520, 265); 
    player.x = 230; 
    player.y = 370; 
    player.cueVideoByUrl("http://www.youtube.com/v/G-P9fO4g2Jc", 0); 
} 

function playVideo(event:MouseEvent):void { 
    player.playVideo(); 
}  

function pauseVideo(event:MouseEvent):void { 
    player.pauseVideo(); 
} 

function muteVideo(event:MouseEvent):void { 
    if(!mute){ 
     player.mute(); 
     mute = true; 
     return; 
    } 
    else { 
     player.unMute(); 
     mute = false; 
    } 
} 

在此先感謝

回答

1

addChild方法將孩子送到孔的動畫片段,而不是設置currentFrame,實際上沒有辦法來添加子爲給框架。

可能的解決方案是:

  1. 在您需要插入播放器,並使用這個精靈,與持票人框架創建空的精靈。不要忘記在離開框架時停止視頻(例如,您可以收聽播放器的Event.REMOVED_FROM_STAGE事件,並停止處理器中的視頻)。

  2. add onEnterFrame事件監聽器並檢查currentFrame屬性,當它的目標幀添加視頻,否則刪除視頻。

+0

謝謝你,我設法使用精靈表只在一個頁面上播放視頻,但我仍然不確定如何停止聲音! – Awilson089

+0

要停止聲音,您需要停止視頻播放。將_REMOVED_FROM_STAGE_事件偵聽器添加到播放器中:_player.addEventListener(Event.REMOVED_FROM_STAGE,onPlayerRemoved)_並在_onPlayerRemoved_中調用_player.pauseVideo(); _ – fsbmain