如果添加了要刪除的對象的痕跡,你會看到你刪除[對象MainTimeline],所以你甚至不需要一個循環。
在您的代碼中刪除[對象MainTimeline]並刪除所有剪輯。 在while循環中,它不會在for循環中引發錯誤。
function removing(e:MouseEvent):void {
var i:int = 0;
for (i=stage.numChildren-1; i>=0; i--)
{
trace("removing : " + (stage.getChildAt(i)));
stage.removeChildAt(i);
}
}
輸出:
removing : [object MainTimeline]
使您免除對象[對象MainTimeline],沒有更多的孩子來去除。
function removing(e:MouseEvent):void {
trace("removing : " + (stage.getChildAt(0)));
stage.removeChildAt(0);
}
可能會給你同樣的輸出:
removing : [object MainTimeline]
所以你不要就算[對象MainTimeline]被刪除需要一個循環。
我沒有在相同的條件下測試它,所以請告訴我們,如果你有相同的輸出。
我建議你檢查從@LukeVanIn,解釋了difference between stage, root and main timeline
[編輯]
function removingWhile(e:MouseEvent):void {
while (stage.numChildren > 0){
count++;
trace("removing : " + (stage.getChildAt(0)));
trace ("number of iterations = " + (count++).toString())
stage.removeChildAt(0);
}
}
將輸出的答案:
刪除:對象MainTimeline] 迭代次數= 1
TypeError:Error#1009 ... 在Untitled_fla :: MainTimeline/removingWhile()
[/編輯]
這避免了錯誤,但刪除[對象MainTimeline]太。 因此,第一次循環後沒有更多的孩子。 @Organis – tatactic