Sound continues to play after unloading external swf

I have a flash application, some playlist that loads an external SWF video player (I don’t have access to the code for this external file), so users can watch the video or switch to another one. When the user switches to another video, a new SWF file is uploaded.

Problem . If the user has not finished watching the video and has not moved on to the next, I unload the previous SWF file ( unloadAndStop()) and upload a new one. And since the previous SWF was playing, it is actually not unloaded, it is still playing in the background (I hear two audio tracks: current and previous).

I tried the call SoundMixer.stopAll(), but it really doesn’t help, due to loading into the background and sound above the current video when it starts playing.

Is there any way to solve this from the main "loader" application?

+3
source share
2 answers

Interestingly, 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 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.

, , ! , unloadAndStop().

Loader, .

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...
}
0
0

Source: https://habr.com/ru/post/1769482/


All Articles