actionscript-3 - 弹性 AS3 : Find and remove elements from container of certain class

标签 actionscript-3 apache-flex containers element

如何仅删除在包含文本输入和按钮的 Bordercontainer 中找到的所有图像?

我尝试过:

for(var i:int=0;i<container.numElements;i++){
if(container.getElementAt(i) is Image){
container.removeElementAt(i);}
}

但正如预期的那样,这个循环并没有完全工作,因为 numElements 发生了变化,这意味着并非所有图像都会被删除。 我知道有一些简单的技巧...但我现在想不起来...请帮助

最佳答案

正如评论者所建议的,似乎向后循环是实现这一点的方法。我会尝试这样的事情:

var totalElements : int = container.numElements;
for(var i:int=totalElements-1;i>=0;i--){
 if(container.getElementAt(i) is Image){
  container.removeElementAt(i);
 }
}

通过在开始循环之前将 numElements 存储在变量中,您可以确保该值在处理循环时不会更改。既然你倒退了,你就不用担心子索引改变了。

第二个选项是在一个循环中对图像实例进行排队,并在第二个循环中使用removeElement 方法将它们删除。我怀疑两个循环方法的性能会明显较差。

关于actionscript-3 - 弹性 AS3 : Find and remove elements from container of certain class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8270147/

相关文章:

apache-flex - 生成 ASDoc 的问题

apache-flex - AS3 : setting registration point of a DisplayObject with actionscript?

java - 管理异构 Java 数组中的不同对象

正则表达式检查字符串中的前 2 个字符是否为字母

actionscript-3 - 如何将 BitmapData 保存到 Bitmap *.bmp 文件,或者更快的 JPE 编码方法

actionscript-3 - 为什么Actionscript 不支持重载?

image - flutter :- Align a icon to the right bottom of a container

闪存 "Double Typing"问题

apache-flex - 在具有调整大小功能的新 Air 窗口中加载外部 SWF 应用程序

docker - 当我不想编辑的Tomcat Docker镜像不以ROOT身份运行时,如何写入ROOT拥有的目录?