# Load and unload in Flash as3 problems?

**URL:** <https://forum.kirupa.com/t/load-and-unload-in-flash-as3-problems/328949>\
**Category:** flash\
**Created:** [July 5, 2012, 7:01pm UTC](https://forum.kirupa.com/t/load-and-unload-in-flash-as3-problems/328949 "2012-07-05T19:01:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bertilvg](https://avatars.discourse-cdn.com/v4/letter/b/b4bc9f/32.png) [@bertilvg](https://forum.kirupa.com/u/bertilvg)\
**Post date:** [July 5, 2012, 7:01pm UTC](https://forum.kirupa.com/t/load-and-unload-in-flash-as3-problems/328949/1 "2012-07-05T19:01:45Z")

</div>

[COLOR=#000000][FONT=verdana]Hi guys, I am using a code snippet in flash cs6 as3, that takes a button and when you click it, it will load a swf, and when you click the button again, it will unload… My question is, can some of you rewrite the code so we actually remove the button, and flash does the work automaticully when it reach a speciel frame?.. What I want is the code to say "when I reach this frame, load this swf, and when I reach another frame, unload it… " I want to use it to a game I am making… Thank you!![/FONT][/COLOR]

[COLOR=#000000][FONT=verdana]Here is the snippet:[/FONT][/COLOR]

[COLOR=#000000][FONT=verdana]/\* Click to Load/Unload SWF or Image from a URL.[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]Clicking on the symbol instance loads and displays the specified SWF or image URL. Clicking on the symbol instance a second time unloads the SWF or image.[/FONT][/COLOR]

[COLOR=#000000][FONT=verdana]Instructions:[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]1. Replace “[http://www.helpexamples.com/flash/images/image1.jpg](http://www.helpexamples.com/flash/images/image1.jpg)” below with the desired URL address of the SWF or image. Keep the quotation marks ("").[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]2. Files from internet domains separate from the domain where the calling SWF resides cannot be loaded without special configuration.[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]\*/[/FONT][/COLOR]

[COLOR=#000000][FONT=verdana]button\_2.addEventListener(MouseEvent.CLICK, fl\_ClickToLoadUnloadSWF\_2);[/FONT][/COLOR]

[COLOR=#000000][FONT=verdana]import fl.display.ProLoader;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]var fl\_ProLoader\_2:ProLoader;[/FONT][/COLOR]

[COLOR=#000000][FONT=verdana]//This variable keeps track of whether you want to load or unload the SWF[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]var fl\_ToLoad\_2:Boolean = true;[/FONT][/COLOR]

[COLOR=#000000][FONT=verdana]function fl\_ClickToLoadUnloadSWF\_2(event:MouseEvent):void[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]{[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]if(fl\_ToLoad\_2)[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]{[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]fl\_ProLoader\_2 = new ProLoader();[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]fl\_ProLoader\_2.load(new URLRequest(“[http://www.helpexamples.com/flash/images/image1.jpg](http://www.helpexamples.com/flash/images/image1.jpg)”));[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]addChild(fl\_ProLoader\_2);[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]}[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]else[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]{[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]fl\_ProLoader\_2.unload();[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]removeChild(fl\_ProLoader\_2);[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]fl\_ProLoader\_2 = null;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]}[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]// Toggle whether you want to load or unload the SWF[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]fl\_ToLoad\_2 = !fl\_ToLoad\_2;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]}[/FONT][/COLOR]
