IDAT102 – Flash Game – Timer and play button 0004-0006

Next I added a timer using the code:

var time = 120;
var count:Number = time;
var myTimer:Timer = new Timer(1000,count);
myTimer.addEventListener(TimerEvent.TIMER, countdown);
myTimer.start();
function countdown(event:TimerEvent):void
{
countTxt.text = String((count)-myTimer.currentCount);
}

This counts down from 120 displaying the current time remaining in countTxt.#

I then created a separate frame for a splash screen at the start of the game. To prevent the game simply playing through the frames as it would an animation, I started the actionscript with stop();. After this I added a button which becomes lighter on mouseover and onclick runs nextFrame();.

I experienced an error when transitioning between frames which I eventually determined to be because of the event listeners on the first frame persisting. To fix this I used:

btnPlay.removeEventListener(MouseEvent.MOUSE_OVER, hoverON);
btnPlay.removeEventListener(MouseEvent.MOUSE_OUT, hoverOFF);

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.