2017-08-29 80 views

回答

1

我猜你會需要遍歷所有子對象,並確定滿足給定條件的一個,然後用removeChild(toBeRemove)toBeRemove移除這些例子是你想要的對象去除。

沒有removeChild()超負荷你想要做什麼,如果有它應該看起來像removeChild("a*")無論如何。我想你想把這個名字作爲一個標準,以實際的變量名作爲標準是不可能的。

1
// Iterate through all the children. 
// Backward loop to not miss children if any of them gets removed. 
for (var i:int = stage.numChildren - 1; i >= 0; i--) 
{ 
    // Get a reference to a child. 
    var aChild:DisplayObject = stage.getChildAt(i); 

    // Check its name and remove if condition is met. 
    if (aChild.name.charAt(0) == "a") stage.removeChildAt(i); 
} 

請記住,這將檢查並刪除附加到直接階段孩子。那些連接到或更深的將不會受到影響。