ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller error - AS

StackOverflow https://stackoverflow.com/questions/2492036

문제

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

도움이 되었습니까?

해결책

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.

다른 팁

Try with:

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

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)) {
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top