# Loading and Unloading External SWFs

**URL:** <https://forum.kirupa.com/t/loading-and-unloading-external-swfs/289425>\
**Category:** flash\
**Created:** [May 30, 2009, 3:30am UTC](https://forum.kirupa.com/t/loading-and-unloading-external-swfs/289425 "2009-05-30T03:30:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![LeonJack](https://avatars.discourse-cdn.com/v4/letter/l/a9adbd/32.png) [@LeonJack](https://forum.kirupa.com/u/LeonJack)\
**Post date:** [May 30, 2009, 3:30am UTC](https://forum.kirupa.com/t/loading-and-unloading-external-swfs/289425/1 "2009-05-30T03:30:42Z")

</div>

[FONT=Arial]I have a question regarding the swapping out of swf[/FONT]  
[FONT=Arial]files in Flash CS3 / AS3. Any help greatly appreciated.[/FONT]  
[FONT=Arial]I’ve been trying to work this out for a few days and have[/FONT]  
[FONT=Arial]found useful tips – but none seem to apply to what I’m[/FONT]  
[FONT=Arial]trying to do. [/FONT]  
[FONT=Arial]I start my project with a “logo” swf, which has no [/FONT]  
[FONT=Arial]interactivity. At the last frame, the following code is[/FONT]  
[FONT=Arial]used to load another swf from the local folder:[/FONT]  
[FONT=Arial] [/FONT]  
[FONT=Arial]-------------------------------------------[/FONT]  
[FONT=Arial]//Stop current swf and stop its sound[/FONT]  
[FONT=Arial] [/FONT]  
[FONT=Arial]stop();[/FONT]  
[FONT=Arial]SoundMixer.stopAll();[/FONT]  
[FONT=Arial] [/FONT]  
[FONT=Arial] [/FONT]  
[FONT=Arial]//Create a loader and pass the name of the [/FONT]  
[FONT=Arial]//swf to be loaded[/FONT]  
[FONT=Arial] [/FONT]  
[FONT=Arial]var myLoader:Loader = new Loader;[/FONT]  
[FONT=Arial]addChild(myLoader);[/FONT]  
[FONT=Arial]var url:URLRequest = new URLRequest(“01.swf”);[/FONT]  
[FONT=Arial]myLoader.load(url);[/FONT]  
[FONT=Arial]--------------------------------------------------[/FONT]  
[FONT=Arial] [/FONT]  
[FONT=Arial]This new swf (“01.swf”) has two buttons, each with a mouse[/FONT]  
[FONT=Arial]click listener which runs code as above except with the urls of[/FONT]  
[FONT=Arial]two different local swfs. These swfs have similar buttons [/FONT]  
[FONT=Arial]to lead to two further swfs, etc. [/FONT]  
[FONT=Arial] [/FONT]  
[FONT=Arial]This works fine – except that, as you’ve probably[/FONT]  
[FONT=Arial]noticed, the current swf is not removed or unloaded. My project [/FONT]  
[FONT=Arial]is to run on a user’s machine, ie, not over the Internet,[/FONT]  
[FONT=Arial]so file-size is not critical – but I presume that eventually all [/FONT]  
[FONT=Arial]these swfs will become stacked in memory and a lock-up or [/FONT]  
[FONT=Arial]crash will occur.[/FONT]  
[FONT=Arial] [/FONT]  
[FONT=Arial]How do I remove and/or unload the previous swf[/FONT]  
[FONT=Arial]when a new one is loaded? and remove that[/FONT]  
[FONT=Arial]previous swf from memory?[/FONT]  
[FONT=Arial]Can I give the current swf access to the previous one,[/FONT]  
[FONT=Arial]then run a “remove” or “unload” function on it?[/FONT]  
[FONT=Arial] [/FONT]  
[FONT=Arial]Or is there a better way to load/unload swfs than[/FONT]  
[FONT=Arial]the above?[/FONT]  
[FONT=Arial] [/FONT]  
[FONT=Arial]I’ve tried to find tips in various AS3 books and on [/FONT]  
[FONT=Arial]forums, but they all assume that new swfs are loaded [/FONT]  
[FONT=Arial]from the same base swf, so that you can use the same[/FONT]  
[FONT=Arial]loader instance from that base and run its unload() function.[/FONT]  
[FONT=Arial]However, I don’t see how I could make my project run[/FONT]  
[FONT=Arial]that way, when the first swf is played once and is then[/FONT]  
[FONT=Arial]not needed anymore. [/FONT]  
[FONT=Arial]Should I create a “dummy” swf, to use as a “container”?[/FONT]  
[FONT=Arial]How would that be done?[/FONT]  
[FONT=Arial] [/FONT]  
[FONT=Arial](If there’s a good book or tutorial which covers this, please[/FONT]  
[FONT=Arial]point me there!)[/FONT]  
[FONT=Arial] [/FONT]  
[FONT=Arial]Grateful thanks in advance![/FONT]  
[FONT=Arial] [/FONT]  
[FONT=Arial] [/FONT]
