按下退出按钮后,如何成功卸载swf,并转到父swf

时间:2016-01-03 11:42:01

标签: actionscript-3 flash

使用 中的代码段,但努力让它真正发挥作用:

我想卸载孩子SWF(这是一个视频)并返回到父SWF(视频选择页面)。尝试了很多不同的方法,需要快速简便的解决方案。感谢。

下面似乎不起作用......

exit_btn.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
{

    fl_ProLoader.unload();
    removeChild(fl_ProLoader);
    fl_ProLoader = null;
}

1 个答案:

答案 0 :(得分:0)

我使用此代码进行了测试

import flash.filesystem.*;
import flash.events.MouseEvent;
import flash.net.*;
import flash.events.*;

var _file: File;
_file = File.documentsDirectory.resolvePath("./Directory to swf file/mySwf.swf");
if (_file.exists) {
    trace("SWF loading ...........");
    displayingSWF(_file.nativePath)
} else {
    trace("the file doesn't exit");
}



//////////////// DIsplay the SWF story file //////////////////
var mLoader: Loader ;
function displayingSWF(lnk) {
    var inFileStream: FileStream = new FileStream();
    inFileStream.open(_file, FileMode.READ);
    var swfBytes: ByteArray = new ByteArray();
    inFileStream.readBytes(swfBytes);
    inFileStream.close();

 mLoader = new Loader();
    var loaderContext: LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
    loaderContext.allowCodeImport = true;
      mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onSwfLoadComplete);
     mLoader.loadBytes(swfBytes, loaderContext);     
}

function onSwfLoadComplete(e: Event): void {
         mLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onSwfLoadComplete);
        addChild(mLoader);
    }
exit_btn.addEventListener(MouseEvent.CLICK, dimising);

function dimising(e: MouseEvent): void {
    mLoader.unloadAndStop();
    removeChild(mLoader);

}