引发ArgumentError:错误#2025:提供的DisplayObject必须是调用错误的孩子 - AS
-
21-09-2019 - |
题
我有一个函数内部此代码段,如果存在于级的对象,并删除它检查:
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);
}
}
我试图改变stage
与this
和root
但总是收到此错误ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller
解决方案
误差信号您试图删除DisplayObject
与removeChild
,显然不是这个代码是从执行DisplayObjectContainer
的子项。
解决这个问题的一种方法是检查您是否尝试删除的对象实际上是使用contains
容器的孩子。你这样做是对一些要删除(submitButton
和saveinfoButton
)的对象,而不是一些人。
尝试包裹为removeChild
,txt
和ldr.content
在if语句在使用_closeButton
检查这些contains
s是否在容器中。
DisplayObject
呼叫 其他提示
尝试用:
e.currentTarget.parent.removeChild(txt);
e.currentTarget.parent.removeChild(ldr.content)
etc.
尝试这种情况:
public function closeContent(e:MouseEvent):void {
removeChild(txt);
removeChild(ldr.content);
removeChild(_closeButton);
container_mc.visible = false;
statusText.text="";
if (contains(submitButton)) {
removeChild(submitButton);
removeChild(saveinfoButton);
}
}
您可能能够在有条件添加两个项目用于去除与&&:
if (contains(submitButton && saveinfoButton)) {
不隶属于 StackOverflow