PDA

View Full Version : How To - Remember Last Loaded Swf



schammy79
April 14th, 2008, 12:14 PM
I want to add some unload function to my master swf, which will obviously unload any external swf already loaded into it, when I click a link to load another external swf...

Here's my unload function:


function unloadFunction(evt:Event):void
{
Loader(evt.target).unload();
}


FYI, here's how I load my external swfs into my master swf.


stage.addEventListener(MouseEvent.CLICK, clickButton);

function clickButton(e:MouseEvent):void {
switch (e.target) {
case this.b1 :
loadVideo(new URLRequest(extSWF[0]));
break;
case this.b2 :
loadVideo(new URLRequest(extSWF[1]));
break;
// etc.
}

function loadVideo(myrequest:URLRequest):void {
var myloader:Loader=new Loader();
myloader.addEventListener("UnloadMe", unloadFunction);
myloader.load(myrequest);
addChild(myloader);

}


Additionally, those external swfs each feature a "close" button that unloads them when clicked... But of course, I am trying to consider the good portion of visitors who would not bother clicking that link before viewing another content... anyways, here below is the code applied to that button:


closebutton.addEventListener(MouseEvent.CLICK, unloadFunction);

function unloadFunction(event:MouseEvent) {
dispatchEvent(new Event("UnloadMe", true));
}

function kill():void {
stage.removeEventListener(MouseEvent.CLICK, unloadFunction);
}