ArgumentError: 错误 #2025: 提供的 DisplayObject 必须是调用者错误的子级 - AS
我在一个函数中包含以下代码片段,该函数检查舞台上是否存在对象并将其删除:
public function closeContent(e:MouseEvent):void {
removeChild(txt);
removeChild(ldr.content);
removeChild(_closeButton);
container_mc.visible = false;
statusText.text="";
if (contains(submitButton)) {
removeChild(submitButton);
}
if (contains(saveinfoButton)) {
removeChild(saveinfoButton);
}
}
我尝试使用 this
和 root
更改 stage
但总是收到此错误ArgumentError:错误#2025:提供的 DisplayObject 必须是调用者的子级
I have this code snippet inside a function that checks if an object exists on stage and removes it:
public function closeContent(e:MouseEvent):void {
removeChild(txt);
removeChild(ldr.content);
removeChild(_closeButton);
container_mc.visible = false;
statusText.text="";
if (contains(submitButton)) {
removeChild(submitButton);
}
if (contains(saveinfoButton)) {
removeChild(saveinfoButton);
}
}
I tried to change stage
with this
and root
but always get this error ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
该错误表明您正在尝试使用
removeChild
删除DisplayObject
,但该DisplayObject
显然不是执行此代码的DisplayObjectContainer
的子级。解决此问题的一种方法是使用
contains
检查您尝试删除的对象是否实际上是容器的子对象。您正在对要删除的某些对象(submitButton
和saveinfoButton
)执行此操作,但不会对其他对象执行此操作。尝试将
txt
、ldr.content
和_closeButton
的removeChild
调用包装在使用contains 的 if 语句中
检查这些DisplayObject
是否在容器中。The error signals that you are trying to remove a
DisplayObject
withremoveChild
that apparently is not a child of theDisplayObjectContainer
this code is executed from.One way to solve this problem is to check if the object you are trying to remove is actually a child of the container using
contains
. You are doing this for some of the objects you are removing (submitButton
andsaveinfoButton
), but not for some others.Try wrapping the
removeChild
calls fortxt
,ldr.content
and_closeButton
in if statements that usecontains
to check whether theseDisplayObject
s are in the container.尝试使用:
Try with:
试试这个:
您可以使用 && 在条件中添加要删除的两项:
Try this:
You may be able to add both items for removal in the conditional with &&: