AS3从加载的SWF本身卸载SWF

时间:2011-09-19 08:50:48

标签: actionscript-3 flash

我一直在弄乱我的AS3代码试图找到一种方法来通过按下加载的SWF中的te close_btn来卸载已加载的swf。 我似乎无法让它工作,所以也许你们知道这样做的方法。

这样:

main_swf加载swf_1。

在swf_1中是close_btn,它应该卸载swf_1。

这样我们就可以回到main_swf。

有什么想法吗?

2 个答案:

答案 0 :(得分:0)

您可以在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

然后将其传递给加载的swf:

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

在加载的swf中你只需要调用它:toCall()

答案 1 :(得分:0)

main_swf有一个loader,可以加载swf_1

我的建议是: 如果close_btn位于swf_1的主要舞台上。点击close_btn时:

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

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 ();
}    

有关unloadAndStop()

的更多信息