2013-01-04 53 views
0

我在Flash上​​創建了一個信息亭,但是我遇到了一個問題,在外部加載我的內容時真的很煩人。我已經導出了所有的swf文件,並創建了一個獨特的swf來加載上面的主菜單上的所有內容。主要問題是從YouTube上流式傳輸視頻。它可以完美加載,但是當我導航到另一個頁面時,頁面會發生變化,但是如果視頻已經播放過一次,視頻就不會停止(聲音不停地播放)。這裏是我的代碼:url請求無法正常工作 - 視頻不會停止as3

loader1.fla:

// Container 
var pageLoader:Loader = new Loader(); 

// Url Requests 
var loadRequest1:URLRequest = new URLRequest("basics1.swf"); 
var loadRequest2:URLRequest = new URLRequest("climatechange.swf"); 

// Initial Page Loaded 
pageLoader.load(loadRequest1) 
addChild(pageLoader) 

// Button Functions 
function goHome (e:MouseEvent):void{ 
pageLoader.load(loadRequest1) 
addChild(pageLoader) 
} 
hpage.addEventListener(MouseEvent.CLICK, goHome); 

//go to climate change page 
function climatePage (e:MouseEvent):void{ 
pageLoader.load(loadRequest2); 
addChild(pageLoader); 
} 
climatep.addEventListener(MouseEvent.CLICK, climatePage); 

climatechange.fla:

Security.allowDomain("http://www.youtube.com") 

// load video 
var pageLoader:Loader = new Loader(); 

// Url Requests 
var loadRequest1:URLRequest = new URLRequest("overviewvideo.swf"); 

// Intial Page Loaded 
pageLoader.load(loadRequest1) 
addChild(pageLoader) 

overviewvideo.fla:

/*youtube video*/ 

var player:Object; 

var loader:Loader = new Loader(); 

var context:LoaderContext = new LoaderContext(); 
context.checkPolicyFile = true; 
context.securityDomain = SecurityDomain.currentDomain; 
context.applicationDomain = ApplicationDomain.currentDomain; 

loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit); 
Security.allowDomain("http://www.youtube.com") 
loader.load(new URLRequest("http://www.youtube.com/v/6s8iiIFgPMU&list=PL9C6D9D2AF8999F85&index=12")); 

function onLoaderInit(event:Event):void { 
    addChild(loader); 
    loader.x= 40; 
    loader.y=130; 
    loader.content.addEventListener("onReady", onPlayerReady); 
    loader.content.addEventListener("onError", onPlayerError); 
    loader.content.addEventListener("onStateChange", onPlayerStateChange); 
    loader.content.addEventListener("onPlaybackQualityChange", onVideoPlaybackQualityChange); 
} 

function onPlayerReady(event:Event):void { 
    // Event.data contains the event parameter, which is the Player API ID 
    trace("player ready:", Object(event).data); 

    // Once this event has been dispatched by the player, we can use 
    // cueVideoById, loadVideoById, cueVideoByUrl and loadVideoByUrl 
    // to load a particular YouTube video. 
    player = loader.content; 
    // Set appropriate player dimensions for your application 
    player.setSize(480, 260); 
} 

function onPlayerError(event:Event):void { 
    // Event.data contains the event parameter, which is the error code 
    trace("player error:", Object(event).data); 
} 

function onPlayerStateChange(event:Event):void { 
    // Event.data contains the event parameter, which is the new player state 
    trace("player state:", Object(event).data); 
} 

function onVideoPlaybackQualityChange(event:Event):void { 
    // Event.data contains the event parameter, which is the new video quality 
    trace("video quality:", Object(event).data); 
} 

誰能幫助?如果有人能幫助我,我會很高興。謝謝

+0

,如果你不清理頁面,並停止視頻,你只是裝在它上面的東西。你需要刪除加載器或頁面 – Gone3d

回答

0

之前加載新的swf到加載器,你需要先電話:

pageLoader.unloadAndStop(); 

嘗試卸載子SWF文件內容並停止執行已加載的SWF文件的命令的執行。此方法嘗試通過刪除對子SWF文件的EventDispatcher,NetConnection,Timer,Sound或Video對象的引用來卸載使用Loader.load()或Loader.loadBytes()加載的SWF文件。因此,子SWF文件和子SWF文件的顯示列表會發生以下情況:

聲音停止。 舞臺事件監聽器被刪除。 刪除enterFrame,frameConstructed,exitFrame,激活和停用的事件偵聽器。 定時器停止。 相機和麥克風實例分離 影片剪輯已停止。

Docs at Adobe

+0

我把pageLoader.unloadAndStop();在我的url上請求loader1.fla上的swf文件,但它不起作用。 –

+0

嘗試也進入加載的swfs(overviewvideo)並偵聽this.loaderInfo上的Event.UNLOAD並調用loader.unloadAndStop()並在該文件中設置loader = null。 –

+0

仍然沒有運氣,我用loaderIn evenlistener創建了event.unload的第二個函數,並把loader.unloadAndStop()和設置loader = null,但仍然沒有做任何事情 –