简体   繁体   中英

Unload and load in actionscript 3

There is a button in a sprite. I want to click that button and load menu.swf and unload the current swf. But only that sprite is removed, not the entire swf. What can I do?

go.addEventListener(MouseEvent.CLICK, fl_ClickToLoadUnloadSWF);

import fl.display.ProLoader;
var fl_ProLoader: ProLoader;

//This variable keeps track of whether you want to load or unload the SWF
var fl_ToLoad: Boolean = true;


function fl_ClickToLoadUnloadSWF(event: MouseEvent): void {
    if (fl_ToLoad) {



        var x: Number = this.numChildren;
        while (x--) {
            this.removeChildAt(x);
        }



        fl_ProLoader = new ProLoader();
        fl_ProLoader.load(new URLRequest("menu.swf"));
        addChild(fl_ProLoader);
        fl_ProLoader.graphics.clear(); 
        fl_ProLoader.x = -245;
        fl_ProLoader.y = -140;
        fl_ProLoader.width = 600;
        fl_ProLoader.height = 850;
        fl_ProLoader.scaleX = 1
        fl_ProLoader.scaleY = 1
    } else {
        fl_ProLoader.unload();
        removeChild(fl_ProLoader);
        fl_ProLoader = null;

        for (var i: int = fl_ProLoader.numChildren - 1; i >= 0; i--) {
            fl_ProLoader.removeChildAt(i);

        }

    }
    // Toggle whether you want to load or unload the SWF
    fl_ToLoad = !fl_ToLoad;
}
var rootContainer:DisplayObjectContainer = DisplayObjectContainer (root);

This gives you a reference to root cast to DisplayObjectContainer. You can now replace this with rootContainer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM