# URLLoader class

**URL:** <https://forum.kirupa.com/t/urlloader-class/276764>\
**Category:** flash\
**Created:** [December 3, 2008, 12:31pm UTC](https://forum.kirupa.com/t/urlloader-class/276764 "2008-12-03T12:31:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![small\_guy](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@small\_guy](https://forum.kirupa.com/u/small_guy)\
**Post date:** [December 3, 2008, 12:31pm UTC](https://forum.kirupa.com/t/urlloader-class/276764/1 "2008-12-03T12:31:05Z")

</div>

Hi,

I’m not new to Flash, but am new to AS 3. Help is appreciated.

I’ve got two buttons (button\_one and button\_two) both through which I am attempting to load external swfs into main fla. My issue is that when say button\_one has already loaded its swf in then when I select button\_two I want button\_one’s content to unload (and vice versa).

Here is the code that I tried but I am getting a compiler error message.

button\_one.addEventListener(MouseEvent.CLICK, justin);  
function justin (e:MouseEvent):void {  
var my\_loaderJustin:Loader = new Loader();  
my\_loaderJustin.load(new URLRequest(“justin.swf”));  
addChild(my\_loaderJustin);  
}

button\_two.addEventListener(MouseEvent.CLICK, ed);  
function ed (e:MouseEvent):void {  
var my\_loaderEd:Loader = new Loader();  
my\_loaderEd.load(new URLRequest(“ed.swf”));  
addChild(my\_loaderEd);  
}

I thought that unload would work. And maybe I am just not using unload correctly. For example in the button\_two code I tried adding this line to the button\_two code (to unload the Justin content of button\_one):

my\_loaderJustin.unload();

and the error message I get is: Access of undefined property’

Hoping that it might (sort of) be like AS 2 where loading in a second content into the loader (as loadMovie had done in AS 2) would automatically unload the first content. But this does not work as both contents are on the stage at the same time (just changing the stacking order of the two).

So how to unload the swfs is the question. Thank you.
