2014-12-20 13 views
0

我簡化了我的問題到這個自解釋代碼。爲什麼舞臺上的每個電影剪輯都沒有轉到第二幀?錯誤發生在第六行。無法通過stage.getChildAt訪問MovieClips的時間軸

stage.addEventListener(Event.ENTER_FRAME,update); 
function update(e:Event) 
{ 
    for (var i:int=0; i<stage.numChildren; i++) 
    { 
     stage.getChildAt(i).gotoAndPlay(2);//error here 
    } 
} 

謝謝你的幫助。

回答

2

getChildAt方法返回DisplayObject(請參閱documentation)的實例,但您試圖調用MovieClip類的成員實例上的方法。您需要將實例返回到正確的類型:

stage.addEventListener(Event.ENTER_FRAME,update); 
function update(e:Event) 
{ 
    for (var i:int=0; i<stage.numChildren; i++) 
    { 
     MovieClip(stage.getChildAt(i)).gotoAndPlay(2); // cast instance to MovieClip 
    } 
} 
+0

這正是我所需要的。謝謝! – DrakeTruber