title: how to remove a child object by removeChild()?
body: <p>I'm trying to make a custom animated/shooter, from this tutorial: <a href="http://flashadvanced.com/creating-small-shooting-game-as3/" rel="nofollow">http://flashadvanced.com/creating-small-shooting-game-as3/</a></p>
  
  <p>By custom, I mean customized, ie, my own version of it.</p>
  
  <p>In it's actionscript, there's a timer event listener with function: timerHandler()
  This function adds and removes child "star" objects on the stage (which the user has to shoot at):</p>
  
  <pre><code>if(starAdded){
  removeChild(star);
  }
  </code></pre>
  
  <p>and :   </p>
  
  <pre><code>addChild(star);
  </code></pre>
  
  <h1>Code works great, but error occurs on scene 2.</h1>
  
  <p>The code works great, and I even added some code while learning via google and stackflow to this flash file. I added Scene 2 to it too, and had it called after 9 seconds of movie time. But when it goes to Scene 2, it still displays the star objects and I've been unable to remove these "star" object(s) from Scene 2.</p>
  
  <h2>Here's the code I added:</h2>
  
  <p>SCENE 1:</p>
  
  <pre><code>var my_timer = new Timer(5000,0); //in milliseconds
  my_timer.addEventListener(TimerEvent.TIMER, catchTimer);
  my_timer.start();
  
  
  var myInt:int = getTimer() * 0.001;
  var startTime:int = getTimer();
  var currentTime:int = getTimer();
  var timeRunning:int = (currentTime - startTime) * 0.001; // this is how many seconds the game has been running.
  demo_txt.text = timeRunning.toString();
  
  function catchTimer(e:TimerEvent)
  {
      gotoAndPlay(1, "Scene 2");
  }
  </code></pre>
  
  <hr>
  
  <p>SCENE 2: </p>
  
  <pre><code>addEventListener(Event.ENTER_FRAME,myFunction);
  function myFunction(event:Event) {
      timer.stop();
      timer.removeEventListener(TimerEvent.TIMER, timerHandler);
      stage.removeChild(star);
      stage.removeEventListener(MouseEvent.MOUSE_MOVE, cursorMoveHandler);
      my_timer.stop(); // you might need to cast this into Timer object
      my_timer.removeEventListener(TimerEvent.TIMER, catchTimer);
      Mouse.show();
  }
  stop();
  </code></pre>
  
  <p>=====================================================</p>
  
  <p>I'm quite new as3, and have just created an account on StackOverflow... even though I've known and read many codes on it since quite some time. </p>
  
  <h1>Here's the Edited New Complete Code:</h1>
  
  <pre><code>//importing tween classes
  import fl.transitions.easing.*;
  import fl.transitions.Tween;
  
  //hiding the cursor
  Mouse.hide();
  
  //creating a new Star instance
  var star:Star = new Star();
  var game:Game = new Game();
  //creating the timer
  var timer:Timer = new Timer(1000);
  //we create variables for random X and Y positions
  var randomX:Number;
  var randomY:Number;
  var t:int = 0;
  //variable for the alpha tween effect
  var tween:Tween;
  //we check if a star instance is already added to the stage
  var starAdded:Boolean = false;
  //we count the points
  var points:int = 0;
  
  //adding event handler on mouse move
  stage.addEventListener(MouseEvent.MOUSE_MOVE, cursorMoveHandler);
  //adding event handler to the timer
  timer.addEventListener(TimerEvent.TIMER, timerHandler);
  //starting the timer
  timer.start();
  addChild(game);
  function cursorMoveHandler(e:Event):void{
      //sight position matches the mouse position
      game.Sight.x = mouseX;
      game.Sight.y = mouseY;
  }
  
  function timerHandler(e:TimerEvent):void{
      //first we need to remove the star from the stage if already added
      if(starAdded){
          removeChild(star);
      }
  
      //positioning the star on a random position
      randomX = Math.random()*500;
      randomY = Math.random()*300;
      star.x = randomX;
      star.y = randomY;
      //adding the star to the stage
      addChild(star);
      //changing our boolean value to true
      starAdded = true;
      //adding a mouse click handler to the star
      star.addEventListener(MouseEvent.CLICK, clickHandler);
      //animating the star's appearance
      tween = new Tween(star, "alpha", Strong.easeOut, 0, 1, 3, true);
  t++;
  if(t&gt;=5) {
      gotoAndPlay(5);
  }
  }
  
  function clickHandler(e:Event):void{
      //when we click/shoot a star we increment the points
      points ++;
      //showing the result in the text field
      points_txt.text = points.toString();
  }
  </code></pre>
  
  <h1>    And on Frame 5 :</h1>
  
  <pre><code>//timer.stop();
      //timer.removeEventListener(TimerEvent.TIMER, timerHandler);
      // uncomment lines above if "timer" is something you've made
      stage.removeChild(star);
      stage.removeEventListener(MouseEvent.MOUSE_MOVE, cursorMoveHandler);
      timer.stop(); // you might need to cast this into Timer object
      timer.removeEventListener(TimerEvent.TIMER, timerHandler);
      Mouse.show();
      stop();
  </code></pre>
  
  <p>There's no Scene 2 now, in this new .fla file...
  Here's a screenshot of the library property of my flash file...: <a href="http://i.imgur.com/d2cPyOx.jpg" rel="nofollow">http://i.imgur.com/d2cPyOx.jpg</a></p>