title: Actionscript 3 resetting a game?
body: <p>I have a memory game here and when the game ends or the timer runs out, the user is brought to a game over page, containing a reset button.</p>
  
  <p>My problem is when I hit the reset button, it brings me back to the main game page, it does all sorts of weird things.</p>
  
  <p>Also, when I get to the game over page, I'm getting errors with my timer.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>package {
  import flash.display.Sprite;
  import flash.events.MouseEvent;
  import flash.events.TimerEvent;
  import flash.utils.Timer;
  import flash.display.MovieClip;
  import flash.text.TextField;
  
  public class MemoryGame extends MovieClip{
  
  private var firstTile:cards;
  private var secondTile:cards;
  private var pauseTimer:Timer;
  private var score:int;
  private var cardCount:int;
  var seconds:Number;
  var minutes:Number;
  
  
  var numberDeck:Array = new Array(1,1,2,2,3,3,4,4,5,5,6,6);
  
  
  public function MemoryGame(){
  
      //TIMER FUNCTION
      var levelTimer:Timer = new Timer(1000, 180);
      levelTimer.addEventListener(TimerEvent.TIMER_COMPLETE, timerCompleteHandler);
      levelTimer.addEventListener(TimerEvent.TIMER, timerHandler);
  
      // LEVEL FUNCTION
      easyBtn.addEventListener(MouseEvent.CLICK, easyButtonClicked);
      medBtn.addEventListener(MouseEvent.CLICK, medButtonClicked);
      hardBtn.addEventListener(MouseEvent.CLICK, hardButtonClicked);
  
      score = 0;
      txtScore.text=""+score;
  
      //Level button events
      function easyButtonClicked(e:MouseEvent):void{
          removeChild(levelText);
          trace("easy button clicked!");
          seconds = 0;
          minutes = 1;
          txtTime.text = "1:00";
          levelTimer.start();
          setupTiles();
      }
  
      function medButtonClicked(e:MouseEvent):void{
          removeChild(levelText);
          trace("medium button clicked!");
          seconds = 30;
          minutes = 0;
          txtTime.text = "0:30";
          levelTimer.start();
          setupTiles();
      }
  
      function hardButtonClicked(e:MouseEvent):void{
          removeChild(levelText);
          trace("hard button clicked!");
          seconds = 15;
          minutes = 0;
          txtTime.text = "0:15";
          levelTimer.start();
          setupTiles();
      }
  
  
      //Timer handlers
      function timerHandler(e:TimerEvent):void {
          if (seconds &gt; 00) {
          seconds -=1;
          }
  
          else {
              if (minutes &gt; 0) {minutes -=1;seconds = 59;}
      }
              txtTime.text = minutes+":"+(seconds &gt;= 10 ? seconds : "0"+seconds);
          }
  
      function timerCompleteHandler(e:TimerEvent):void {
          e.target.reset();
          e.target.stop();
  
      }
  
  
  
      //Tiles set up
      function setupTiles(){
      for(x=1; x&lt;=4; x++) {
          for (y=1; y&lt;=3; y++){
              var randomCard = Math.floor(Math.random()*numberDeck.length);
              var tile:cards = new cards();
              tile.card = numberDeck[randomCard];
              numberDeck.splice(randomCard,1);
              tile.gotoAndStop(9);
              tile.x = (x-0.5) * 150;
              tile.y = (y-0.5) * 200;
              tile.addEventListener(MouseEvent.CLICK,tileClicked);
              addChild(tile);
              cardCount = cardCount + 1
          }
      }
  }
  
  
  }
  
  
  
  
  public function tileClicked(event:MouseEvent) {
      var clicked:cards = (event.currentTarget as cards);
      if (firstTile == null){
          firstTile = clicked;
          firstTile.gotoAndStop(clicked.card);
      }
  
      else if (secondTile == null &amp;&amp; firstTile != clicked){
          secondTile = clicked;
          secondTile.gotoAndStop(clicked.card);
          if (firstTile.card == secondTile.card){
              pauseTimer = new Timer(1000, 1);
              pauseTimer.addEventListener(TimerEvent.TIMER_COMPLETE,removeCards);
              pauseTimer.start();
  
          }
          else {
              pauseTimer = new Timer(1000, 1);
              pauseTimer.addEventListener(TimerEvent.TIMER_COMPLETE,resetCards);
              pauseTimer.start();
          }
      }
  
      if (seconds == 0){
          pauseTimer.stop();
          this.gotoAndStop(3);
  
  
      }
  }
  
  
  public function resetCards(event:TimerEvent) {
      firstTile.gotoAndStop(9);
      secondTile.gotoAndStop(9);
      firstTile = null;
      secondTile = null;
      pauseTimer.removeEventListener(TimerEvent.TIMER_COMPLETE,resetCards);
      score = score - 2;
      txtScore.text=""+score;
  }
  
  
  public function removeCards(event:TimerEvent){
      removeChild(firstTile);
      removeChild(secondTile);
      firstTile = null;
      secondTile = null;
      pauseTimer.removeEventListener(TimerEvent.TIMER_COMPLETE,removeCards);
      score = score + 10;
      txtScore.text=""+score;
      cardCount = cardCount - 2;
      trace("Cardcount: " + cardCount);
  
      if (cardCount == 0){
  
  
          this.gotoAndStop(2);
          txtFinalScore.text=" "+score;
          pauseTimer.stop();          
          }
              }
  }   
  }
  </code></pre>
  
  <p>And here is my code for the reset button:</p>
  
  <pre><code>button_3.addEventListener(MouseEvent.CLICK, resetGame);
  
  function resetGame(event:MouseEvent):void
  {
  score = 0;
  seconds = 0;
  pauseTimer.stop();
  
  this.gotoAndStop(1);
  
  }
  </code></pre>