Reputation: 449
Why is that if i remove everything from stage, then i can't add anything back? It just became blank.
if(stage.numChildren > 0)
{
stage.removeChildAt(0);
}
var s5:Autodetail= new Autodetail ();
addChild(s5);
Upvotes: 0
Views: 154
Reputation: 314
For the sake of completeness, since Flash Player 11 you can simply call:
stage.removeChildren();
to remove all children from the stage or any DisplayObjectContainer.
Upvotes: 1
Reputation: 24
You are trying to add s5 variable in context of current DisplayObject. It is not necessarily your stage and I guess it is exactly DisplayObject has been deleted by stage.removeChildAt(0).
Solution: use while loop and this instead of stage. It'll clean current childrens up while this
object becomes stage's child.
Code:
if(this.numChildren > 0)
{
this.removeChildAt(0);
}
var s5:Autodetail= new Autodetail ();
this.addChild(s5);
Upvotes: 1
Reputation: 106
There should be a while loop to remove all the children from the stage:
while(stage.numChildren > 0)
{
stage.removeChildAt(0);
}
You should be able to add new things to the stage. Is there something wrong with
new Autodetail ()
?
Upvotes: 1