ArgumentError: 错误 #2025: 提供的 DisplayObject 必须是调用者错误的子级 - AS

发布于 2024-08-26 06:15:08 字数 561 浏览 9 评论 0原文

我在一个函数中包含以下代码片段,该函数检查舞台上是否存在对象并将其删除:

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

我尝试使用 thisroot 更改 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

苯莒 2024-09-02 06:15:08

该错误表明您正在尝试使用 removeChild 删除 DisplayObject,但该 DisplayObject 显然不是执行此代码的 DisplayObjectContainer 的子级。

解决此问题的一种方法是使用 contains 检查您尝试删除的对象是否实际上是容器的子对象。您正在对要删除的某些对象(submitButtonsaveinfoButton)执行此操作,但不会对其他对象执行此操作。

尝试将 txtldr.content_closeButtonremoveChild 调用包装在使用 contains 的 if 语句中 检查这些 DisplayObject 是否在容器中。

The error signals that you are trying to remove a DisplayObject with removeChild that apparently is not a child of the DisplayObjectContainer 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 and saveinfoButton), but not for some others.

Try wrapping the removeChild calls for txt, ldr.content and _closeButton in if statements that use contains to check whether these DisplayObjects are in the container.

π浅易 2024-09-02 06:15:08

尝试使用:

e.currentTarget.parent.removeChild(txt);  
e.currentTarget.parent.removeChild(ldr.content)  
etc.

Try with:

e.currentTarget.parent.removeChild(txt);  
e.currentTarget.parent.removeChild(ldr.content)  
etc.
寂寞花火° 2024-09-02 06:15:08

试试这个:

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)) {

Try this:

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

You may be able to add both items for removal in the conditional with &&:

    if (contains(submitButton && saveinfoButton)) {
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文