如何以编程方式访问 DisplayObject 的所有子级?
如何使用代码访问 DisplayObject 的所有子级? (我正在寻找类似于movieclip.children的东西)
我在两种情况下使用它:
1)循环并重新定位封闭MovieClip的所有子项。
或者
2) 循环并删除 MovieClip 的所有子项
另外,这是一个 Flash CS5 项目。
How do access all of the children of a DisplayObject using code? (I'm looking for something like movieclip.children
)
I'm using this in two cases:
1) To loop through and reposition all of the children of an enclosing MovieClip.
Or
2) To loop through and delete all of the children of a MovieClip
Also, this is a Flash CS5 project.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这个循环将触及 movieclip foo 内的每个子元素。我不确定你要对它们做什么,但你可以在循环内运行你需要的任何方法。
This loop will touch every child inside movieclip foo. I'm not sure what you're going to do to them, but you can run whatever methods you need inside the loop.
您的对象只是一个显示对象吗?如果它是 UIComponent,您可以使用 getChildAt() 和 getChildByName() 以及 numChildren 属性来循环它们。这是 Flex 项目的一部分还是仅 ActionScript 项目的一部分?
DisplayObject 本身没有描述其子对象的机制。了解子级的最低级别类型是 DisplayObjectContainer。您可能必须将该对象至少转换为 DisplayObjectContainer 才能执行您想要的操作。如果您有可以使用的 Flex 框架,我会选择 UIComponent。
DisplayObject
DisplayObjectContainer
UIComponent
Is your object just a display object? If it is an UIComponent, you could use getChildAt() and getChildByName() along with the numChildren property to loop over them. Is this part of a flex project or an actionscript only project?
A DisplayObject itself does not have the mechanisms to describe its children. The lowest level type that knows about children is the DisplayObjectContainer. You may have to convert the object into at least a DisplayObjectContainer to be able to do what you want. I would go with an UIComponent though if you have the flex framework to work with.
DisplayObject
DisplayObjectContainer
UIComponent
如果您需要访问所有孩子,包括孩子的孩子,您可以尝试
这:
If you need to access all the children, inclusive of a child's children, you can try
this: