views:

52

answers:

1
if (theData.hasOwnProperty("@id1")) {
    var myObj:Hello = new Hello();
    textArea.visible = false;               
    panel.addChild(myObj);
} else if (theData.hasOwnProperty("@id2")) {
    textArea.visible = false;
    var vijay:MCQ = new MCQ();
    panel.addChild(vijay);
}

When i click on the next item, the previous window is still visible. How can i destroy myObj. I am not able to do it through removeChild.

+1  A: 

If panel only ever contains one object, you could use the following before adding the new one:

panel.removeAllChildren();

If there are a known number of "static" children in panel, you could conditionally remove the additional ones:

while (panel.numChildren > EXPECTED) {
    panel.removeChildAt(panel.numChildren - 1);
}

The best option would be to hold a reference to the object you added so that you can remove it explicitly using removeChild(). If these alternatives won't work, perhaps you could explain your constraints.

Chris Thornhill
I'd like to point out that removeAllChildren is a Flex only thing, NOT AS3 in general, such as for Flash, so that no one gets confused :)
Bryan Grezeszak