我有一个函数内部此代码段,如果存在于级的对象,并删除它检查:

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);
    }
}

我试图改变stagethisroot但总是收到此错误ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller

有帮助吗?

解决方案

误差信号您试图删除DisplayObjectremoveChild,显然不是这个代码是从执行DisplayObjectContainer的子项。

解决这个问题的一种方法是检查您是否尝试删除的对象实际上是使用contains容器的孩子。你这样做是对一些要删除(submitButtonsaveinfoButton)的对象,而不是一些人。

尝试包裹为removeChildtxtldr.content在if语句在使用_closeButton检查这些containss是否在容器中。

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)) {
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top