0
    public function SeedsAndPots()

    {
        startpage = new StartPage();
        addChild(startpage);

        buttonPage = new ButtonPage();
        addChild(buttonPage);
        buttonPage.addEventListener(MouseEvent.CLICK, GoToGame);    

    }
    public function GoToGame(e:MouseEvent):void
    {
        removeChild(startpage);
        buttonPage.removeEventListener(MouseEvent.CLICK, GoToGame);
        removeChild(buttonPage);
        gamePage = new GamePage();
        addChild(gamePage);

    }

// I wanna do a function that says that if time is 0 i should go to my GameOver-Page.
}
}

Bruno Alves
  • 51
  • 1
  • 1
  • 7

1 Answers1

0

Create a countdown variable to reflect time in seconds.

Instantiate a timer when you load your game page to countdown every second.

When time has reached 0, apply the logic to end the current level and display your game over page.

    // store time remaining in a countdown timer
    protected var countdown:uint = 60;

    // create a timer, counting down every second
    protected var timer:Timer;

    // in your go to game, or when you want to start the timer      
    public function GoToGame(e:MouseEvent):void
    {
        // ... your go to game function

        // start your countdown timer.
        timer = new Timer(1000);
        timer.addEventListener(TimerEvent.TIMER, timerHandler);
        timer.start();
    }

    protected function timerHandler(event:TimerEvent):void
    {
        // countdown a second
        --countdown;

        // update any counter time text field display here...

        // if you've reached 0 seconds left
        if(countdown == 0)
        {
            // stop the timer
            timer.removeEventListener(TimerEvent.TIMER, timerHandler);
            timer.reset();

            // remove current gamePage
            // addChild to your game over page.
        }
    }
Jason Sturges
  • 15,855
  • 14
  • 59
  • 80