Flex AS3:从特定类的容器中查找并删除元素
如何仅删除在包含 Textinputs 和 Buttons 的 Bordercontainer 中找到的每个图像?
我尝试过:
for(var i:int=0;i<container.numElements;i++){
if(container.getElementAt(i) is Image){
container.removeElementAt(i);}
}
但正如预期的那样,这个循环并没有完全工作,因为 numElements 发生了变化,这意味着并非所有图像都会被删除。 我知道这有一些简单的技巧...但我现在想不起来...请帮助
How can I remove only every image found in a Bordercontainer which also holds Textinputs and Buttons ?
i tried:
for(var i:int=0;i<container.numElements;i++){
if(container.getElementAt(i) is Image){
container.removeElementAt(i);}
}
But as expected this loop does not fully work since the numElements changes which means that not all Images get removed.
I know there is some simple trick to this...but I cant think of it right now...Please help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如评论者所建议的,似乎向后循环是实现这一目标的方法。我会尝试这样的事情:
通过在开始循环之前将 numElements 存储在变量中,您可以确保该值在处理循环时不会改变。既然你倒退了,你就不必担心子索引的变化。
第二个选项是在一个循环中对图像实例进行排队,并在第二个循环中使用removeElement 方法将它们删除。我怀疑两个循环方法的性能会明显较差。
As commenters have suggested, it seems like looping backwards would be the way to do it. I'd try something like this:
By storing the numElements in a variable before starting the loop, you can be sure that the value will not change while processing the loop. Since your going backwards, you don't have to worry about the child index changing.
A second option would be to queue up the image instances in one loop and remove them in a second loop using the removeElement method. I suspect the two loop method will have significantly worse performance.
向后循环是实现此目的的一种方法。
另一个是
Looping backwards would be 1 way to do this.
Another would be