0
votes

I have created a flash player that loads external swfs and control them through stop, play, frwd buttons. the external swf is added on next previous buttons click using loader class.

to remove the preiously added SWF and add new one I use the following code

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. I can't simply stop all sounds because I'll have other SWFs with sound. and nothing seems to work with sound stream even unloadAndStop please help.

2
Have you considered disabling the buttons while loading/unloading processes?Sam DeHaan
No, I didn't try disabling button, but I intend this for elearing purposes and I think this might annoy the students.Eng.Maisoon
I would do some button disabling as well while loading like Sam said.ToddBFisher
What happens if you execute l.close(); before anything else? Also, why aren't you using weak referencing for the IO error handling in addition to ProgressEvent.PROGRESS and Event.COMPLETE? Weakly referencing the loader object 2 times out of 3 won't actually help. :)Eric deRiel
I tried using weak reference but it didn't help, I also added l.close() but I got the following error: Error #2029: This URLStream object does not have a stream opened. at flash.display::Loader/close() at Lo_flash2_fla::MainTimeline/Add_Content() at Lo_flash2_fla::MainTimeline/Start_Display() at Lo_flash2_fla::MainTimeline/Complete_Handler() at flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at flash.net::URLLoader/onComplete()Eng.Maisoon

2 Answers

0
votes

To stop all sounds you can try SoundMixer.stopAll(); before you call your load(), and maybe even before l.unloadAndStop(). I've never used it for loaded swfs but it's worth a try.

0
votes

The Problem is Fixed for now

here is what I used to remove the old externally loaded 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

externally loaded SWF with Audio. Hope this works for others