actionscript-3movieclip

Deleting everything from the stage AS3


So, I am wanting to clear my whole stage. I already searched through the internet, and unfortunately nothing has worked for my situation.

Basically, what I am doing is a somewhat complex maze generator and before I create a new one, I want to get rid of everything I created prior to that. So far, I hear that the best way to remove movieclips from the stage is buy using:

while(numChildren > 0)
    removeChildAt(0);

However this only works for the current movieclip I call it in, which doesn't include the maze I generated. I just want to get rid of absolutely everything. Any ideas on how to do this?


Solution

  • You're thinking along the right lines, you can use numChildren and removeChildAt however you need to call them in the scope of the stage:

    while(stage.numChildren > 0)
    {
      stage.removeChildAt(0);
    }