简体   繁体   English

如何完全停止和卸载AS3中外部加载的SWF声音?

[英]How to completely stop and unload external loaded SWF sounds in AS3?

I have created a flash player that loads external swfs and control them through stop, play, frwd buttons. 我创建了一个Flash Player,可以加载外部swf并通过停止,播放和frwd按钮对其进行控制。 the external swf is added on next previous buttons click using loader class. 外部swf添加在使用加载程序类单击的下一个先前按钮上。

to remove the preiously added SWF and add new one I use the following code 删除之前添加的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);

every thing works fine as loading complete before I click the next button, I face an issue when I click next quickly before loading the previous content completed. 在单击下一步之前,完成加载后一切正常,在加载上一个内容之前快速单击下一步时,我会遇到问题。 the loader seems to continue loading the previous content and add its sound to stage, the sounds don't seem to stop even though its not within the current SWF. 加载程序似乎会继续加载以前的内容并将其声音添加到舞台上,即使它不在当前的SWF中,声音似乎也不会停止。 I can't simply stop all sounds because I'll have other SWFs with sound. 我不能简单地停止所有声音,因为我将拥有其他带有声音的SWF。 and nothing seems to work with sound stream even unloadAndStop please help. 而且似乎没有任何声音可以播放,即使unloadAndStop也请帮助。

To stop all sounds you can try SoundMixer.stopAll(); 要停止所有声音,您可以尝试SoundMixer.stopAll(); before you call your load() , and maybe even before l.unloadAndStop() . 在调用load()之前,甚至可能在l.unloadAndStop()之前。 I've never used it for loaded swfs but it's worth a try. 我从未将其用于加载的瑞士法郎,但值得一试。

The Problem is Fixed for now 该问题目前已解决

here is what I used to remove the old externally loaded SWF 这是我用来删除旧的外部加载的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);

but mostly what helped was SoundMixer.stopAll() and having a stop at the end of the 但最有帮助的是SoundMixer.stopAll(),并在结尾处下来

externally loaded SWF with Audio. 带有音频的外部 SWF文件。 Hope this works for others 希望这对其他人有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM