Copy link to clipboard
Copied
Hello Everyone..
This is very important query for me.
I've 3 SWFs, 1st parent and 2 other child SWFs. Both Child SWFs have its own audio/voiceover.
I used script from code snippets section which is 'click to Load/Unload SWF or Image'. So i linked both child swf to parent swf using 2 separate buttons in parent swf.
Finally when i click on any button in parent swf to call child swf, it's working fine and if i click again on same button, it unloads successfully but my problem is when it unloads swf, sound keep plays on background.
What to do for complete unload with sound?
Looks like only video unloads but the audio of child swf keep plays in background. How can i unload audio of child swf permanently ?
I tried 'click to stop all sound' but looks like it's only mutes the sound, not unloads.
Plz help! this is very important for me.
Code which i'm using right now in parent swf-
button_1.addEventListener(MouseEvent.CLICK, fl_ClickToLoadUnloadSWF);
import fl.display.ProLoader;
var fl_ProLoader:ProLoader;
//This variable keeps track of whether you want to load or unload the SWF
var fl_ToLoad:Boolean = true;
function fl_ClickToLoadUnloadSWF(event:MouseEvent):void
{
if(fl_ToLoad)
{
fl_ProLoader = new ProLoader();
fl_ProLoader.load(new URLRequest("Child !.swf"));
addChild(fl_ProLoader);
}
else
{
fl_ProLoader.unload();
removeChild(fl_ProLoader);
fl_ProLoader = null;
}
// Toggle whether you want to load or unload the SWF
fl_ToLoad = !fl_ToLoad;
}
Hi.
This happens because you're using the ProLoader class and the method this class has to unload doesn't necessarily destroys the child, references, stops sound, and so on.
...
Removes a child of this ProLoader object that was loaded by using the load()
method. Theproperty
of the associated ProLoaderInfo object is reset tonull
. The child is not necessarily destroyed because other objects might have references to it; however, it is no longer a child of the ProLoader object.
Copy link to clipboard
Copied
Hi.
This happens because you're using the ProLoader class and the method this class has to unload doesn't necessarily destroys the child, references, stops sound, and so on.
Removes a child of this ProLoader object that was loaded by using the load()
method. Theproperty
of the associated ProLoaderInfo object is reset tonull
. The child is not necessarily destroyed because other objects might have references to it; however, it is no longer a child of the ProLoader object.
Loader - Adobe ActionScript® 3 (AS3 ) API Reference
I think you should instead opt for the Loader class and use the unloadAndStop method.
Attempts to unload child SWF file contents and stops the execution of commands from loaded SWF files. This method attempts to unload SWF files that were loaded using
Loader.load()
orLoader.loadBytes()
by removing references to EventDispatcher, NetConnection, Timer, Sound, or Video objects of the child SWF file. As a result, the following occurs for the child SWF file and the child SWF file's display list:
- Sounds are stopped.
- Stage event listeners are removed.
- Event listeners for
enterFrame
,frameConstructed
,exitFrame
,activate
anddeactivate
are removed.- Timers are stopped.
- Camera and Microphone instances are detached
- Movie clips are stopped.
When you call the
unloadAndStop()
method, the Loader object'scontentLoaderInfo
property is set tonull
. Any visual assets that were loaded with the SWF are unloaded and removed from memory. ActionScript class definitions in the loaded SWF remain in memory, and code in the same application domain as the loaded SWF can access instances of those classes and create new instances.
Loader - Adobe ActionScript® 3 (AS3 ) API Reference
Regards,
JC
Copy link to clipboard
Copied
unloadAndStop() works for me!
Thanks !
Copy link to clipboard
Copied
You're welcome!