有趣的是,unloadAndStop()的目的是爲您的具體情況。 按照文檔...
Example: A SWF file that has a music track is loaded into an application.
Later, the SWF is unloaded using Loader.unload().
Though the SWF will be removed from the screen, the music will still be heard.
SOLUTION
Loader.unloadAndStop is a new addition to Action Script 3's API.
It helps developers to correctly stop and unload loaded content
using the Loader.load/loadBytes APIs.
...Flash Player recursively attempts to stop and clear as many
objects as possible (Sounds, NetStreams, EventListeners, etc.)
within the loaded SWF. This feature is especially useful
when unloading unknown 3rd party content.
這似乎正好適合你的情況!假如你的Loader實現 是正確的,這聽起來像是在unloadAndStop()方法中的一個錯誤。
一種替代解決方案是創建裝載機的新實例,而不是使用相同的裝載機爲每個視頻。
private var currentMovie:DisplayObject;
private function loadSWF(url:String):void
{
if(currentMovie != null)
{
//stop the sound playing in the current movie
//then remove it from the display list
removeChild(currentMovie);
currentMovie = null;
}
var loader:Loader = new Loader();
//configureListeners
request.url = url;
loader.load(request , context);
}
private function onLoadComplete(event:Event):void
{
currentMovie = event.target.loader.content;
//etc...
}
使用多個裝載機我有完全一樣的問題:如果用戶跳過50個播放視頻,他們將用50個流的播放端了。另外,如果我沒有記錯,unloadAndStop在Flash 10中引入,但外部SWF可能與'loader'不同,不知道它是否會影響函數的行爲。 – 2010-10-14 06:41:53
好了,這個想法是在當前視頻被卸載後,加載器有資格進行垃圾回收,因爲這些對象不應該有任何引用。現在,如果沒有任何效果,您可以隨時檢測用戶跳到下一個視頻並停止播放當前正在播放的視頻中的聲音,但這只是一個美化補丁,它不是一個真正的解決方案 – PatrickS 2010-10-14 07:09:31
我已經提到我無法訪問外部文件,如果我有我可以簡單地關閉它的網絡流。但感謝您的幫助。 – 2010-10-14 08:32:20