2016-01-03 43 views
0

使用代碼片段之後,但掙扎了它的實際工作:如何成功卸載SWF,並轉到父SWF,按下退出鍵

我想卸載孩子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; 
} 
+0

了''fl_ToLoad如何跟蹤是否要加載或卸載'SWF '?完成你所有的代碼,也許錯誤在其他部分。 – ElChiniNet

回答

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

} 
+0

我試過了,沒有工作......代碼的其餘部分是否正確?...這個按鈕叫做exit_btn。我需要添加任何東西或刪除任何信息嗎?謝謝 – Omar

+0

謝謝Kare81隊友 – Omar