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.
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:
(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?