如何在AS3中完全停止和卸载外部加载的SWF声音?
问题描述:
我创建了一个flash播放器,它可以加载外部swf并通过停止,播放,frwd按钮来控制它们。外部swf被添加到前一个按钮上点击使用loader类。如何在AS3中完全停止和卸载外部加载的SWF声音?
删除蛔虫加入SWF文件,并添加新的一个我用下面的代码
l.unloadAndStop();
l.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, loadProgress);
l.contentLoaderInfo.removeEventListener(Event.COMPLETE, loadHandler);
l.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, loadError);
var Request:URLRequest = new URLRequest(xmlData.Page[Current_Page_No].URL[0]);
l = new Loader();
l.load(Request);
l.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress,false,0,true);
l.contentLoaderInfo.addEventListener(Event.COMPLETE, loadHandler,false,0,true);
l.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loadError);
每一件事工作正常,如加载完成之前,我点击下一步按钮,我面临着一个问题,当我点击下一步之前快速加载之前完成的内容。 加载器似乎继续加载之前的内容并将其声音添加到舞台,即使它不在当前的SWF中,声音似乎也不会停止。我不能简单地停止所有的声音,因为我将有其他的SWF声音。并没有什么似乎与声音流甚至unloadAndStop请帮助。
答
问题得到解决,现在
这里是我用来去除旧的外部加载SWF
//stop all sounds
SoundMixer.stopAll();
System.gc();//force Grabage collection (might not work)
while (Container.numChildren > 0){ Container.removeChildAt(0); }//remove from stage
try
{
currentSWF.stop();//Stop the Loaded Movie clip copy
while (currentSWF.numChildren > 0){ currentSWF.removeChildAt(0); }//remove all children
currentSWF = null;//null its reference
}
catch(er:*)
{
trace("MC null");
}
l.unloadAndStop(true);//unload the loader
l.unload();
// remove event listeners
l.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, loadProgress);
l.contentLoaderInfo.removeEventListener(Event.COMPLETE, loadHandler);
l.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, loadError);
但主要是什么帮助是SoundMixer.stopAll()并具有停止
外部加载SWF与音频。希望这适用于其他人
答
要停止所有声音,您可以在致电load()
,甚至可能在l.unloadAndStop()
之前尝试SoundMixer.stopAll();
。我从来没有用它加载swfs,但值得一试。
您是否考虑在加载/卸载过程中禁用按钮? – 2012-01-09 13:48:07
不,我没有尝试禁用按钮,但我打算这样做的目的,我认为这可能会惹恼学生。 – 2012-01-09 13:55:15
我会做一些按钮禁用,以及像Sam说的加载。 – ToddBFisher 2012-01-09 18:30:22