vendredi 25 décembre 2015

Unload SWF File in a Same Button that Load the External File to Minimize Loading Time

I have two SWF files. First one is home.swf and the second one is menu.swf. Each SWF file has a button that load external SWF file.

This is the code inside home.swf file:

stop();
menu_btn.addEventListener(MouseEvent.CLICK, func_menu);
function func_menu(e:MouseEvent):void {
    var loader:Loader = new Loader();
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
    loader.load(new URLRequest("menu.swf"));
}

function onComplete(e:Event):void {
    var movie:* = LoaderInfo(e.currentTarget).content;
    stage.addChild(movie);
}

This is the code inside menu.swf file:

stop();
home_btn.addEventListener(MouseEvent.CLICK, func_home);
function func_home(e:MouseEvent):void {
    var loader:Loader = new Loader();
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
    loader.load(new URLRequest("home.swf"));
}

function onComplete(e:Event):void {
    var movie:* = LoaderInfo(e.currentTarget).content;
    stage.addChild(movie);
}

If I click the buttons numerous times, the SWF files gets longer time to load. I notice that those code doesn't unload files. What code do I need to unload the previous SWF files? I'm new in actionscript. Please go easy on me.

Aucun commentaire:

Enregistrer un commentaire