Reputation:
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.
Upvotes: 0
Views: 113
Reputation: 5431
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.
Upvotes: 1