# To load and unload SWF

**URL:** https://forum.kirupa.com/t/to-load-and-unload-swf/296795
**Category:** flash
**Created:** [September 20, 2009, 11:17pm UTC](https://forum.kirupa.com/t/to-load-and-unload-swf/296795 "2009-09-20T23:17:35Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![jkl30](https://avatars.discourse-cdn.com/v4/letter/j/5e9695/32.png) [@jkl30](https://forum.kirupa.com/u/jkl30)
#### Post date: [September 20, 2009, 11:17pm UTC](https://forum.kirupa.com/t/to-load-and-unload-swf/296795/1 "2009-09-20T23:17:35Z")

</div>

Hello,

I am studying AS3 by myself, please bear with me if my explanation is not that clear.

## It’s all about loading and unloading external swf’s. My code is working perfectly though I just have some questions about load and unload issues.

I have three buttons on the stage and it should load its external SWF

homeButton\_btn - home.swf  
page1Button\_btn - page1.swf  
page2Button\_btn - page2.swf

Each of the button should load it’s external SWF’s intro when click.  
My problem is that I don’t know how to command the button to play the swf’s outro and then load the next swf everytime I click a button

Example:

When I click homeButton\_btn, the external swf should load “home.swf” and then if I am going to click page1Button\_btn, the outro of "home.swf’ should play and then once it reaches the end of it’s timeline, it should load “page1.swf”.

Same goes with page2Button\_btn, whatever swf that is on the stage should play it’s outro first and then load “page2.swf”

My questions are:

1. How can I control the external SWF to play it’s outro and then load the next SWF.

2. What code should I put at the end of the external SWF’s timeline.

3. Where do you think I should put the preloader? Is it better to put it at the external swf timeline? or on my main swf timeline?

4. Does load and unload of external swf also work with movieclips? Like for example I will not use a external swfs, instead I will use movieclips to load and unload its content.

Thanks!!

* * *

My Actionscript 3.0 code

var pageContainer:Loader;  
pageContainer = new Loader();  
var nextMov:String;  
addChild(pageContainer);

homeButton\_btn.addEventListener(MouseEvent.CLICK,o nHomeButtonClick);  
function onHomeButtonClick(pEvent:MouseEvent) {  
nextMov = “home.swf”  
pageContainer.load(new URLRequest(nextMov));

}

page1Button\_btn.addEventListener(MouseEvent.CLICK, onPage1Click);  
function onPage1Click(pEvent:MouseEvent) {  
nextMov = “page1.swf”  
pageContainer.load(new URLRequest(nextMov));

}

page2Button\_btn.addEventListener(MouseEvent.CLICK, onPage2Click);  
function onPage2Click(pEvent:MouseEvent) {  
nextMov = “page2.swf”  
pageContainer.load(new URLRequest(nextMov));

}
