# Questions about Load and Unload external swf files

**URL:** <https://forum.kirupa.com/t/questions-about-load-and-unload-external-swf-files/264568>\
**Category:** flash\
**Created:** [June 27, 2008, 10:04am UTC](https://forum.kirupa.com/t/questions-about-load-and-unload-external-swf-files/264568 "2008-06-27T10:04:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex298](https://avatars.discourse-cdn.com/v4/letter/a/76d3ee/32.png) [@alex298](https://forum.kirupa.com/u/alex298)\
**Post date:** [June 27, 2008, 10:04am UTC](https://forum.kirupa.com/t/questions-about-load-and-unload-external-swf-files/264568/1 "2008-06-27T10:04:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Felixz](https://avatars.discourse-cdn.com/v4/letter/f/ecb155/32.png) [@Felixz](https://forum.kirupa.com/u/Felixz)\
**Post date:** [June 27, 2008, 7:27pm UTC](https://forum.kirupa.com/t/questions-about-load-and-unload-external-swf-files/264568/2 "2008-06-27T19:27:29Z")

</div>

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?
