views:

41

answers:

1

I have a flash application, some kind of a play-list that loads external SWF video player (I don't have code access to that external file), so users can watch the video or skip to another one. When user switches to another video new SWF file is being loaded.

The problem: If user didn't finish watching the video and skips to the next then I unload previous SWF file (unloadAndStop()) and load a new one. And because the previous SWF was playing it is not actually unloaded, it is still playing on the background (I hear two audio tracks: current and previous).

I tried SoundMixer.stopAll() call, but it doesn't actually help, because of the loading on the background and and sound over the current video when it starts playing.

Is there a way to solve this from the main 'loader' application?

A: 

Interestingly enough, unloadAndStop() was intended for your exact situation. According to the docs...

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.

This seems to exactly fit your situation! Provided your Loader implementation is correct , this sounds like a bug in the unloadAndStop() method.

One alternative solution could be to create a new instance of the Loader as opposed to using the same loader for each videos.

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...
}
PatrickS
With multiple loaders I have exactly the same problem: if user skips 50 playing videos, they'll end up with 50 open streams playing. Also, if I remember correctly unloadAndStop was introduced in flash 10, but external SWF's may not be the same version as 'the loader', don't know if it may affect function's behaviour.
negative
Well the idea was for the loader to be eligible for garbage collection after the current video has been unloaded since there shouldn't be any reference left to those objects. Now if nothing works, you can always detect when a user skips to the next video and stop the sound on the video currently playing but that's only a cosmetic patch , it's not really a solution
PatrickS
I already mentioned that I have no access to the external file, if I had I could just simply close its networkstream. But thanks for the help.
negative
for some reason i thought you may still have access to some public methods, never mind...
PatrickS