Hello,
I have a small project to load and unload two external swf files. Here’s the details of my project:
- There are two external swf files (glow.swf and down.swf)
- Button movie1_btn is used to load glow.swf
- Button movie2_btn is used to load down.swf
- 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:
-
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?
-
Why myLoader.numChildren is always zero? Isn’t the external movie loaded into the myLoader?
-
Any possible problem with the above codes?
Thanks and best regards
Alex