使用removeChildAt删除子项而不删除最后一个子项

时间:2015-03-20 14:28:52

标签: actionscript-3 actionscript removechild

我现在正在制作一个节目,我想删除除了前五个孩子以外的所有孩子。我正在使用这个程序:

while (numChildren > 6) {
        removeChildAt(6);
}

但我现在有另一个问题。我也不想删除舞台的最后3个孩子。有没有办法实现它?

2 个答案:

答案 0 :(得分:1)

如果可能的话,根据他们的名字删除孩子会更可靠,而不是索引。

但如果没有,你可以在你的情况下增加数字。

while (numChildren > firstChildrenCount + lastChildrenCount) {
    removeChildAt(firstChildrenCount)

答案 1 :(得分:0)

var nFromStart : int = 5; // number of children to remain in the start
var nFromEnd   : int = 3; // number of children to remain in the end
for (var childI: int = numChildren - nFromEnd - 1; childI > nFromStart - 1; childI--)
{
  removeChildAt(childI);
}