# Load...unload...etc. same old same old

**URL:** <https://forum.kirupa.com/t/load-unload-etc-same-old-same-old/306175>\
**Category:** Uncategorized\
**Created:** [March 10, 2010, 8:16pm UTC](https://forum.kirupa.com/t/load-unload-etc-same-old-same-old/306175 "2010-03-10T20:16:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ccbayer](https://avatars.discourse-cdn.com/v4/letter/c/bcef8e/32.png) [@ccbayer](https://forum.kirupa.com/u/ccbayer)\
**Post date:** [March 10, 2010, 8:16pm UTC](https://forum.kirupa.com/t/load-unload-etc-same-old-same-old/306175/1 "2010-03-10T20:16:10Z")

</div>

hi-  
like so many others before me, i’m complaining about the unload function in relation to the Loader object.

i want to basically load a new SWF every time a nav button is pressed. i need to get rid of the swf that’s in there already.

```auto

var mLoader:Loader = new Loader();
function LoadNewMovie(movienum)
{

//half-assed attempted to remove swf that's in there already, doesn't work
if(mLoader != null && contains(mLoader)){
        mLoader = null;
        removeChild(mLoader);
        mLoader.unloadAndStop();
    }

var mRequest:URLRequest = new URLRequest("demo_"+movienum+".swf");
// this doesn't work:
//mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, clearChild);

mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
mLoader.load(mRequest);
}
function onCompleteHandler(loadEvent:Event)
{        
        addChild(loadEvent.currentTarget.content);
}
function onProgressHandler(mProgress:ProgressEvent)
{
var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
trace(percent);
}

```

here is how i’m calling the function:

```auto
(root as MovieClip).mc_nav.bt_next.addEventListener(MouseEvent.CLICK, AdvanceDemo);

function AdvanceDemo(event:MouseEvent):void{
    /* load next demo*/
    var nextDemo = currentDemo + 1;
    if(nextDemo > Demos.length - 1){
        nextDemo = Demos.length - 1;
    }
    currentDemo = nextDemo;
    LoadNewMovie(currentDemo);
}

```

i have read tons about this subject (well, a bit) and i think i’m doing this right, but it still ain’t working. as far as i know, i’m not creating a new instance every time, but i could be wrong. it just keeps putting more and more swfs on stage.

I tried adding a mLoader.unload(); on the button functions, and removeChild() with no dice. am i missing something?
