# Loading and Unloading an SWF file

**URL:** <https://forum.kirupa.com/t/loading-and-unloading-an-swf-file/316797>\
**Category:** flash\
**Created:** [December 2, 2010, 4:57pm UTC](https://forum.kirupa.com/t/loading-and-unloading-an-swf-file/316797 "2010-12-02T16:57:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgdarland](https://avatars.discourse-cdn.com/v4/letter/m/8baadc/32.png) [@mgdarland](https://forum.kirupa.com/u/mgdarland)\
**Post date:** [December 2, 2010, 4:57pm UTC](https://forum.kirupa.com/t/loading-and-unloading-an-swf-file/316797/1 "2010-12-02T16:57:57Z")

</div>

**Loading and Unloading an SWF file** I’m currently working on a educational project for e-learning. This project has multiple buttons for opening several specific SWF files. What I want to accomplish is to be able to use my container file with 3 primary buttons for the named SWF files and have them load in a specific location in the container SWF. Then I have a separate button that just needs to close the loaded SWF file. FYI, the 3 primary buttons will be covered by the loaded swf file. I’m including my AS3 code for review. I can load a SWF and close it once. After that, it doesn’t work. I would appreciate any assistance.

**Code:**

stop();  
sub1.about\_btn.addEventListener(MouseEvent.CLICK, aboutLoad);  
sub1.pdf\_btn.addEventListener(MouseEvent.CLICK, pdfLoad);  
sub1.myvideo\_btn.addEventListener(MouseEvent.CLICK , videoLoad);  
sub1.quiz\_btn.addEventListener(MouseEvent.CLICK, quizLoad);

function aboutLoad(e:MouseEvent):void {  
loadClip(“about.swf”);  
}  
function pdfLoad(e:MouseEvent):void {  
loadClip(“pdf.swf”);  
}

function videoLoad(e:MouseEvent):void {  
loadClip(“myvideo.swf”);  
}

function quizLoad(e:MouseEvent):void {  
loadClip(“quiz.swf”);  
}

var theLoader = new Loader();

theLoader.contentLoaderInfo.addEventListener(Progr essEvent.PROGRESS, progHandler);  
theLoader.contentLoaderInfo.addEventListener(Event .COMPLETE, loadedHandler);

addChild(theLoader);  
theLoader.x=102;  
theLoader.y=85;  
back1\_btn.addEventListener(MouseEvent.CLICK, backClick);

function backClick(event:MouseEvent):void {  
removeChild(theLoader);

```
}

```

function loadClip(t:String):void {  
SoundMixer.stopAll();  
var myUrl:URLRequest=new URLRequest(t);  
theLoader.load(myUrl);  
}

preText.visible=false;

function progHandler(e:ProgressEvent):void {  
preText.visible=true;  
var myPercent = Math.floor((e.bytesLoaded/e.bytesTotal)\*100);  
preText.text=“loading: “+myPercent+”%”;  
}

function loadedHandler(e:Event):void {  
preText.visible=false;  
}  
Best,

Monte Darland
