我有一堆图像。 这些图像都加入到一个精灵容器:无法删除精灵容器的所有图像
var container:Sprite = new Sprite();
container.addChild(img);//added in a loop
addChild(container);
后来,当我通过容器循环,除去我说的图片:
for(var i:int=0;i<container.numChildren;i++)
{
var currImg:Sprite = container.getChildAt(i) as Sprite;
container.removeChild(currImg);
}
只有图像的一部分被删除。如果我跟踪container.numChildren,我会得到正确数量的要删除的图像。 有人有同样的问题吗?
另一件事是关于人们发布的代码+你自己的代码。在for循环中,您正在循环中投射变量“i”。尽量避免这种情况。在循环外部投射int,以便可以在for循环外部访问范围内的“i”,并在运行循环之后取消引用(即,在使用for循环的情况下)。循环不需要这个)。 – 2011-05-20 17:16:19
“while”的方法完美工作,谢谢 – algro 2011-05-20 17:50:28
for循环将工作,如果你改变getChildAt(i)getChildAt(0) – 2011-05-20 18:02:18