2011-07-06 77 views
0

我需要加載一個SWF文件到一個新的SWF電影。我需要檢查最後一幀來啓動一個影片剪輯,等等。在下面的代碼中,一切正常。我正在使用as3,並加載了一個外部as3 swf電影。當我收到消息時試圖加載外部as2 swf電影時出現問題:TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::symbol_name to flash.display.MovieClip。有沒有一種方法可以將以下代碼轉換爲as2?有另一種方法嗎?請注意我是一個絕對的Flash初學者,我已經盡最大努力在as3中做到這一點,現在我沒有看到任何其他選擇,只能使用as2!非常感謝!加載外部as2電影

var swfLoader:Loader = new Loader(); 
var swfFile:URLRequest = new URLRequest("file.swf"); 
var container:MovieClip= new MovieClip(); 

swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoadedHandler); 

var currentSWF:MovieClip = new MovieClip(); 

swfLoader.load(swfFile); 

container.addChild(swfLoader); 
addChild(container); 

function swfLoadedHandler(e:Event):void { 
    currentSWF = MovieClip(swfLoader.content); 
    currentSWF.addEventListener(Event.ENTER_FRAME, checkLastFrame); 

    function checkLastFrame(e:Event):void { 
     if (currentSWF.currentFrame == currentSWF.totalFrames) { 
      currentSWF.stop(); 
      bob.play(); 
      if (bob.currentFrame == 2) { 
       bob.stop(); 
      } 
     }  
    } 
} 

回答

0

對於將AS2內容加載到AS3的問題有一個很好的答案:Load AS2 SWF Into AS3 SWF and pass vars in URL。基本上,如果你不能編輯你正在加載的AS2內容,你將需要在AS2中創建一個橋接加載器。

編輯:這(未經測試)的代碼應該做的事情,你就需要在AS2:

import mx.utils.Delegate; 

var mcLoader:MovieClipLoader = new MovieClipLoader(); 
mcLoader.onLoadComplete = Delegate.create(this, loadComplete); 
var targetMC:MovieClip = createEmptyMovieClip("container",getNextHighestDepth(); 
mcLoader.loadClip("file.swf",targetMC); 

function loadComplete(evt:Object):Void { 
    targetMC.onEnterFrame = Delegate.create(this,checkFrame); 
} 

function checkTargetFrame(evt:Object):Void { 
    if(targetMC._totalframes == targetMC._currentframe) { 
     targetMC.stop(); 
     targetMC.onEnterFrame = null; 
     bob.onEnterFrame = Delegate.create(this,checkBobFrame); 
     bob.play(); 
    } 
} 

function checkBobFrame(e:Object):Void { 
    if(bob._currentframe == 2) { 
     bob.onEnterFrame = null; 
     bob.stop(); 
    } 
} 
+0

添加AS2範例 – shanethehat