flash as3提供的索引超出范围

flash as3提供的索引超出范围,flash,actionscript-3,Flash,Actionscript 3,我试图在用户交互时删除电影剪辑中的子项,但它说“提供的索引超出了范围”-然而,我肯定遗漏了一些内容,因为它似乎没有任何内容超出范围。这是我的代码: 圆圈.as: for (var i=0; i<3;i++){ //this number should be based on the number of children found in the XML var wedge:Wedge = new Wedge(wedgeHolderRef, i, cr,cScale)

我试图在用户交互时删除电影剪辑中的子项,但它说“提供的索引超出了范围”-然而,我肯定遗漏了一些内容,因为它似乎没有任何内容超出范围。这是我的代码:

圆圈.as:

for (var i=0; i<3;i++){ //this number should be based on the number of children found in the XML
            var wedge:Wedge = new Wedge(wedgeHolderRef, i, cr,cScale);
        }

for(var i=0;i您不应该从0迭代到存储在那里的子级数,因为
i
在某个点上会超过实际的子级数。每次删除一个时,子级数都会减少

而是这样做:

while(wedgeHolderRef.numChildren)
{
    wedgeHolderRef.removeChildAt(0);
} 

您不应该从0迭代到存储在那里的子级数,因为
i
在某个点上会超过实际的子级数。每次删除一个时,子级数都会减少

而是这样做:

while(wedgeHolderRef.numChildren)
{
    wedgeHolderRef.removeChildAt(0);
} 

删除子项时,索引不考虑子项数量的减少

在一次迭代后,numChildren下降1,但您的索引仍然基于原始子计数

while (wedgeHolderRef.numChildren > 0)
    wedgeHolderRef.removeChildAt(0);

删除子项时,索引不考虑子项数量的减少

在一次迭代后,numChildren下降1,但您的索引仍然基于原始子计数

while (wedgeHolderRef.numChildren > 0)
    wedgeHolderRef.removeChildAt(0);