# Unloading an External SWF

**URL:** https://forum.kirupa.com/t/unloading-an-external-swf/320940
**Category:** flash
**Created:** [April 6, 2011, 7:33am UTC](https://forum.kirupa.com/t/unloading-an-external-swf/320940 "2011-04-06T07:33:15Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![audioholic](https://avatars.discourse-cdn.com/v4/letter/a/f14d63/32.png) [@audioholic](https://forum.kirupa.com/u/audioholic)
#### Post date: [April 6, 2011, 7:33am UTC](https://forum.kirupa.com/t/unloading-an-external-swf/320940/1 "2011-04-06T07:33:15Z")

</div>

Hi,

I’m building a site that has 7 sections. 1 section is a Photo Gallery for which I’m loading an external SWF file that is controlled by an XML file. Im doing this for allowing content editing any time.

All of the other content on the site is one-time, no backend required.

I’ve successfully loaded the external swf file into a loader in one of the frames. However, when I navigate away to the other 6 sections, I’m unable to unload the external SWF loader. How do I go about this?

Here’s my code that loads the external SWF in one frame:

```auto
import flash.events.MouseEvent;

//This creates a new instance of the loader object.
var my_Loader:Loader = new Loader();

//This creates a new instance of the URLRequest object that contains the
//path to the external SWF.
var my_url:URLRequest=new URLRequest("gallery.swf");

//These listeners detect when the file has finished loading, and if the
//correct file is loaded.
my_Loader.contentLoaderInfo.addEventListener(Event.COMPLETE, finishLoading);
my_Loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);

//The load method then loads the SWF file into the loader object.
my_Loader.load(my_url);

//This will offset the load SWF file, so be appear at (20, 20) on the stage.
my_Loader.x = 37.85;
my_Loader.y = 74.90;

//This function adds the external SWF to the stage.
function finishLoading(loadEvent:Event) {
addChild(loadEvent.currentTarget.content);
}

//This function displays a message if the file is not found.
function errorHandler(errorEvent:Event):void {
trace("file missing");
}

stop();

```

Here’s the code I’m using for the site navigation buttons. I tried adding my\_Loader.unload(); for all of the button Event listener functions. Its still not working.

```auto
import flash.events.MouseEvent;

vinaybtn.addEventListener(MouseEvent.CLICK, vinay);

function vinay(event:MouseEvent):void
{
    my_Loader.unload();
    gotoAndStop(2);
}

priyabtn.addEventListener(MouseEvent.CLICK, priya);

function priya(event:MouseEvent):void
{
    gotoAndStop(3);
}

gallerybtn.addEventListener(MouseEvent.CLICK, gallery);

function gallery(event:MouseEvent):void
{
    gotoAndStop(4);
}

bestwishesbtn.addEventListener(MouseEvent.CLICK, bestwishes);

function bestwishes(event:MouseEvent):void
{
    my_Loader.unload();
    gotoAndStop(5);
}

invitationbtn.addEventListener(MouseEvent.CLICK, invitation);

function invitation(event:MouseEvent):void
{
    gotoAndStop(6);
}

rsvpbtn.addEventListener(MouseEvent.CLICK, rsvp);

function rsvp(event:MouseEvent):void
{
    gotoAndStop(7);
}

```

Any help would be much appreciated.

Thanks,  
Sudarshan
