views:

27

answers:

2

Hi,

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

A: 

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.

Ravi Gummadi
Hi Ravi Gummadi, Thank you for your message. The button that I'd like to remove is in the main app. (There is a yes/no radio button in the TitleWindow. But, I don't need to do anything with the TitleWindow.) I tried hBox1.removeChild(lastButtonClicked) and it worked. But, the problem is that I have other buttons that are not in hBox1. I tried this.removeChild(lastButtonClicked) but that didn't work. If oyu have any suggestions, please let me know. Thank you.
Laxmidi
I've got the buttons in the main app in several HBoxes. The HBoxes are, in turn, inside of a VBox called mainVBox. I tried mainVBox.removeChild(lastButtonClicked), but that didn't work, either.
Laxmidi
A: 

Hi,

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

Laxmidi
k, it's the one , answered by Amarghosh, so Laxmidi u started working,
Ankur Sharma