URLLoader class

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.