ActionScript 3.0 参数错误:2025(删除子问题)
每当我在 Adobe Flash CS4 中编译项目时,我都会遇到以下错误消息:
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at stageRotation/spawnParticle()
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()
生成错误的代码如下所示:
for (var i:int = 0; i < particleArrayForward.length; i++ ) {
if (particleArrayForward[i] != null) {
trace("particleArrayForward[" + i + "]:" + particleArrayForward[i]);
this.removeChild(particleArrayForward[i]);
}
}
任何输入都值得赞赏。谢谢。 :)
I am encountering the following error message whenever I compile my project in Adobe Flash CS4:
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at stageRotation/spawnParticle()
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()
the code that generates the error is shown below:
for (var i:int = 0; i < particleArrayForward.length; i++ ) {
if (particleArrayForward[i] != null) {
trace("particleArrayForward[" + i + "]:" + particleArrayForward[i]);
this.removeChild(particleArrayForward[i]);
}
}
Any input appreciated. Thanks. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当传递的参数不是调用该方法的父级的子级时,
removeChild
会引发此错误。粒子是否作为子级添加到this
对象内的另一个子容器中?确保它确实是调用者的子级:
如果粒子不是
this
对象的直接子级,您可以使用以下方法删除它们:removeChild
throws this error when the passed argument is not a child of the parent that called the method. Are particles added as child to another sub-container withinthis
object?Make sure it is indeed a child of the caller:
If the particles are not direct children of
this
object, you can remove them using:您可以通过循环遍历数组中的所有粒子来从显示对象中删除子项。但是,我看不到您在哪里删除对数组本身中子级的引用。因此,如果您再次循环粒子ArrayFoward,您将尝试删除已删除的显示对象,我假设正在发生这种情况?
更好的是:
否则,如果您不再循环遍历该数组,那么您在数组中的某个位置添加了一个子项,该子项不是您要从中删除的显示对象的子项。
You are removing a child from display object by looping through all the particles in the array. However I can not see where you then remove the reference to the child in the array itself. So if you loop through particleArrayFoward again you will be trying to remove a display object that was already removed which I am going to assume is happening?
so better yet:
otherwise if you are not looping through that array again then somewhere you are adding a child to the array that is not a child of the display object of which you are trying to remove from.