开发者

Flex 3 Error #2025 when using removeChild

开发者 https://www.devze.com 2023-01-19 07:19 出处:网络
I\'m getting a Flex ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.

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(lastButto开发者_运维百科nClicked), but it didn't work. Thank you.

Thank you.

-Laxmidi


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消