Question

I'm getting a Flex ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.

This is what I've got:

a) I set the variable lastButtonClicked to the last button that was clicked in the main app.

private var lastButtonClicked:DisplayObject;

    private function lastButtonClickedFunction(event:MouseEvent):void {
        lastButtonClicked = event.currentTarget as DisplayObject;

    }

b) I have a TitleWindow open and there is a yes/no option. I have a custom event return the answer to the main app.

c) In the main app, I'm trying to remove lastButtonClicked based on the data sent by the custom event. So, my problem is in this function. For some reason it won't let me remove the button. I get Error 2025 instead.

private function answerHandler( event:AnswerEvent ):void {
        if(event.answerCorrect == true){
            removeChild(lastButtonClicked);
        }
    }

Any suggestions on how to debug this problem? The custom event is firing okay. How do I fix this line: removeChild(lastButtonClicked); ?

Edit: I tried hbox1.removeChild(lastButtonClicked) and it worked. The proper button was removed from the main app. The problem is that not all of the buttons are in hBox1. I've got other HBoxes. So, I need to figure out a more generic way instead of using hBox1 in the statement. I tired this.removeChild(lastButtonClicked), but it didn't work. Thank you.

Thank you.

-Laxmidi

Was it helpful?

Solution 2

I solved it. I made a variable and set it to the parent of lastButtonClicked.

private var myParent:Object; myParent = lastButtonClicked.parent;

Then in my answerHandler I wrote:

myParent.removeChild(lastButtonClicked);

Thank you.

-Laxmidi

OTHER TIPS

From what I understand, it seems like you have the buttons in a TitleWindow and the event handler in the application. You probably want to call removeChild for the instance of TitleWindow (eg: titleWindow.removeChild(lastButtonClicked) ) rather than from the application.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top