title: AS3 : How to remove movieclip properly without Error 1009 overflow?
body: <p>I have a class Catcher which lets you control a movieclip in a game. I'm trying to program the game so it finishes and you can restart. So I need to remove everything and go back to the menu. Should be a simple thing to solve but I can't seem to find out how.</p>
  
  <p>So far I just have ourCatcher.parent.removeChild(ourCatcher); to remove my movieclip from the stage. And an if statement to stop one of the functions which drops things onto the stage. SoundMixer.stopAll(); to stop the music.Then I just have it going to frame 3 which is the gameover screen.</p>
  
  <p>It looks fine but I get constant 1009 errors overflowing in the error console and when I  restart the game, it's super slow. It seems the function for movement within Catcher is still running and creating an error because the Catcher was removed from stage and is null now.</p>
  
  <p>I know I need to un-reference everything to do with the Catcher but I can't find out any documentation online to do it in my situation. Everyone seems to have different methods which I've tried and don't work.</p>
  
  <p>The two functions in the Catcher class I'm using to move the character :</p>
  
  <pre><code>public function Catcher(stageRef:Stage) 
      {
          stop();
          this.stageRef = stageRef;
          key = new KeyObject(stageRef);
  
  
          addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
      }
  
      //movement
      public function loop(e:Event):void
      {           
          if (key.isDown(Keyboard.A))
                  vx -= walkSpeed;
  
          else if (key.isDown(Keyboard.D))
                  vx += walkSpeed;
  
          else
                  vx *= friction;
  
          //update position
          x += vx;
  
          //speed adjustment
          if (vx &gt; maxspeed)
              vx = maxspeed;
          else if (vx &lt; -maxspeed)
              vx = -maxspeed;
  
          //stay inside screen
          if (x &gt; stageRef.stageWidth)
          {
              x = stageRef.stageWidth;
              vx = -vx
          }
  
          else if (x &lt; 0)
  
          {
              x = 0;
              vx = -vx;
          }
  
  
          if (key.isDown(Keyboard.A))
          {
              scaleX = -1;
          }
  
          else if (key.isDown(Keyboard.D))
          {
              scaleX = 1;
          }
  
          movement();
  
          // Jumping
          jump += gravity;
  
          if (y &gt; stage.stageHeight /1.5)
          { 
              jump = 0;
              canJump = true;
          }
  
          if (key.isDown(Keyboard.SPACE) &amp;&amp; canJump)
          {
              jump = -10;
              canJump = false;
          }
  
          y += jump;
  
  
      }
  </code></pre>
  
  <p>The other class where I'm removing the things from the stage is called CatchingGame and it has a function which drops objects, I put the game over code there for when playerlives == 0 .</p>
  
  <pre><code>if (playerLives == 0 )
                  {
                  stop();
                  ourCatcher.parent.removeChild(ourCatcher);
                  SoundMixer.stopAll();
                  gotoAndStop(3);
                  }
  </code></pre>
  
  <p>I've probably made an elementary mistake since this is my first flash game. Any help is greatly appreciated as this is pretty much the last step in finishing my game.</p>