2014-02-13 54 views
0

我有一個外部SWF,我打算使用它來加載影片剪輯,其內容需要能夠在不更改源文件的情況下進行更改。從應用程序目錄中加載的外部SWF不會加載兩次

我得到它加載完美,一切運行良好,然後我卸載它,將值設置爲null只是爲了安全,應用程序仍然運行良好沒有錯誤,但是當我嘗試再次加載它時,我的痕跡顯示它加載100%,但最終的onComplete函數似乎不會觸發,除非我再次單擊加載按鈕,但它會加載另一個swf副本。

任何人都會遇到類似的事情或知道發生了什麼?

編輯:下面的代碼示例:

var swfFileName:String = "path/to/file.swf"; 
      var swfFilePath:File = File.applicationStorageDirectory.resolvePath(swfFileName); 
      var inFileStream:FileStream = new FileStream(); 
      inFileStream.open(swfFilePath, FileMode.READ); 
      var swfBytes:ByteArray = new ByteArray(); 
      inFileStream.readBytes(swfBytes); 
      inFileStream.close(); 

      var loader:Loader = new Loader(); 
      var loaderContext:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain); 
      loaderContext.allowCodeImport = true; 
      loader.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoaded); 
      loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, imageLoading); 
      loader.contentLoaderInfo.addEventListener(ErrorEvent.ERROR, loadError); 
      loader.loadBytes(swfBytes, loaderContext); 

這是去除代碼:

function remover(event:Event = null):void { 
        loader.unloadAndStop(); 
        loader = null; 
        swfFileName = null; 
        swfBytes = null; 
        loaderContext = null; 
        trace("removed"); 
       } 

有一個在swfLoaded功能增加了一些內容,並刪除卸妝功能,但是我已經刪除了這些以試圖縮小這個例子中的原因。從我已完成的跟蹤中,Progress事件中的百分比跟蹤是在第二次加載該函數期間沒有其他事件發生之前發生的最後一次事件。我第一次嘗試運行它時,它運行良好,並顯示具有完美功能的所有內容。

+1

分享您的代碼。我們的心靈感應器仍然很弱。 ;) – Atriace

+0

你是如何卸載SWF的? –

回答

0

我最終解決了這個問題。事實證明,這一行:

new LoaderContext(false,ApplicationDomain.currentDomain);

由於某種原因,我沒有完全理解,導致它脫離上下文去除。我通過允許默認設置運行來修復它:

new LoaderContext();

唯一的缺點是我必須做更多的工作來加載和使用外部swf中的庫對象,但現在它再次工作。