title: Removing movieclips from the stage
body: <p>I am working on a side-scrolling game in Flash Actionscript 3.0.  Right now I am trying to allow the Player to advance to the next level by touching a certain object.  Before the next level is loaded, I try to remove all of the previous level's assets (background and "floor"), which are MovieClips, from the stage.  When the next level loads, I can still see the previous level's assets, although the Player cannot interact with them.</p>
  
  <p>I have looked around the Internet and tried a few methods to fix my problem, but I have gotten nowhere.  Following is the code I use to transition from one level to the next.  the 'bgContainer' contains only the unloaded level's background MovieClip and the 'allContainer' contains the unloaded level's floor and other environmental objects.  These containers are later loaded with the objects required in the next level.</p>
  
  <pre><code>// Check if the Player has touched Level 1's end point
      private function checkLevel1To2Collision(event:Event):void {
          // Has the Player touched Level 1's end point?
          if (HitTest.intersects(player, level1To2, this)) {
  
                  // Remove Level 1's Background from the stage
                  //stage.removeChild(bgContainer);
  
                  removeEventListener(Event.ENTER_FRAME, scrollScreen);
  
                  // Clear everything from the stage (only if there is already something on the stage)
                  //while (numChildren &gt; 0) {
  
                      //for (var stgIndex = 0; stgIndex &lt; stage.numChildren; stgIndex++) {
                          //stage.removeChildAt(0);
                      //}
                  //}
                  //}
  
                  stage.removeChild(allContainer);
                  stage.removeChild(bgContainer);
  
                  // Clear out all elements from the 'allContainer' before reloading the current level
                  for (var allIndex1:int = 0; allIndex1 &lt; allContainer.numChildren; allIndex1++) {
                      allContainer.removeChildAt(allIndex1);
                      //if (stage.getChildAt(allIndex1)) {
                          //stage.removeChildAt(allIndex1);
                      //}
                  }
  
                  // Remove the elements within 'bgContainer' from the stage
                  for (var bgIndex1:int = 0; bgIndex1 &lt; bgContainer.numChildren; bgIndex1++) {
                      bgContainer.removeChildAt(bgIndex1);
                      //if (stage.getChildAt(bgIndex1)) {
                          //stage.removeChildAt(bgIndex1);
                      //}
                  }
  
  
                  // Load Level 2
                  loadLevel2(event);
          }
      } // End of 'checkLevel1To2Collision' function  
  </code></pre>
  
  <p>As can be seen, I have tried at least two techniques to the unload the previous level's assets.  I have tried going through the stage and removing all elements one by one using a 'for' loop.  And I have tried removing the stage element at index 0 while the stage has an object on it. I also tried referring to 'root' instead of 'stage' while adding objects using 'addChildAt().'  None of those techniques worked.  I still have no idea why the previous level will not be unloaded.</p>
  
  <p>Any help would be appreciated!</p>
  
  <p>Thanks!</p>