开发者

AS3 unloading SWF from loaded SWF itself

I've been messing with my AS3 codes trying to find a way to get a loaded swf unloaded by pressing te close_btn which is in the loaded SWF. I can't seem to get that to work, so Ma开发者_开发知识库ybe you guys know a way to do this.

so:

main_swf loads swf_1.

And in swf_1 is the close_btn which should unload swf_1.

So that we get back to main_swf.

Any ideas?


you can declare a following function in main_swf:

private function killSWF1():void{
    _loader.unloadAndStop();
}

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Loader.html#unloadAndStop%28%29

and then pass it into the loaded swf:

private function onInit(e:Event):void{
    _mc = loader.content as MovieClip;
    _mc['toCall'] = killSWF1;
    addChild(_mc);
}

and in the loaded swf you'll have just to call it: toCall()


main_swf has a loader which loads your swf_1.

my suggestion would be: If close_btn is on the main stage of the swf_1. When a close_btn gets clicked:

function handleClose ( e : MouseEvent ) : void
{
    // this needs to be in the root section of the swf_1
    this.dispatchEvent ( new Event ( Event.CLOSE ) );
}

inside the main_swf after the swf_1 has been loaded:

loader.content.addEventListener ( Event.CLOSE, handleContentClosed );

function handleContentClosed ( e : Event ) : void
{
    // removing the event listener, making the content ready for GC
    loader.content.removeEventListener( Event.CLOSE, handleContentClosed );
    // removing the actual content from the place it was added
    removeChild ( loader.content );
    // unloading and stoppping the loaded swf
    loader.unloadAndStop ();
}    

more info about unloadAndStop()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜