Questions about Load and Unload external swf files

Hello,

I have a small project to load and unload two external swf files. Here’s the details of my project:

  1. There are two external swf files (glow.swf and down.swf)
  2. Button movie1_btn is used to load glow.swf
  3. Button movie2_btn is used to load down.swf
  4. Button remove_btn is used to remove either glow.swf or down.swf

The codes are as below and seems to work.

// Create a new Loader to load the swf files
var myLoader:Loader=new Loader();

// Set the location of the new Loader
myLoader.x=120;
myLoader.y=150;

// function to load the “glow.swf”

function loadMovie1(evt:MouseEvent):void {
// Is unload is required??
myLoader.unload();

var myrequest:URLRequest=new URLRequest("glow.swf");
myLoader.load(myrequest);
stage.addChild(myLoader);

}

movie1_btn.addEventListener(MouseEvent.CLICK, loadMovie1);

// function to load the “down.swf”

function loadMovie2(evt:MouseEvent):void {
//Is unload is required??
myLoader.unload();

var myrequest:URLRequest=new URLRequest("down.swf");
myLoader.load(myrequest);
stage.addChild(myLoader);

trace("Number of children in myLoader: " + myLoader.numChildren);

}

movie2_btn.addEventListener(MouseEvent.CLICK, loadMovie2);

// Function to remove the Loader

function removeMovie(evt:MouseEvent):void{
myLoader.unload();
stage.removeChild(myLoader);
}

remove_btn.addEventListener(MouseEvent.CLICK, removeMovie);

I am very new to AS 3. My concept is still very poor. I have some questions:

  1. Why the loadMovie1 function and loadMovie2 function still working after I click the remove_btn to remove the myLoader? It seems that myLoader is not removed when removeMovie function is executed. It is still on the MainTimeline. Is it possible to really remove it?

  2. Why myLoader.numChildren is always zero? Isn’t the external movie loaded into the myLoader?

  3. Any possible problem with the above codes?

Thanks and best regards

Alex

It is enough to add loader instance once,
Calling unload before load is pointless since loader unloads clips automatically when new request is passed,
I’d recommend adding clips to root instead of stage.
Question 1: How you remove loader? Do you want to remove it completely?