Advertisement |
AS3 Countdown Timer - Creating a Simple Countdown Timer in Flash Using ActionScript 3
Step 11
In the event listener function, we want to subtract nCount by 1 so that each time the function gets called, nCountwill decrease. And then we'll display the new value in the timer_txt text field again so that it gets updated.
Step 12
Lastly, let's make sure that we start the timer using the start() method of the Timer class. If we don't start the timer, then we won't see anything happen.
Step 13
Test the movie. You should now have a working countdown timer.
In the event listener function, we want to subtract nCount by 1 so that each time the function gets called, nCountwill decrease. And then we'll display the new value in the timer_txt text field again so that it gets updated.
var nCount:Number = 10;
var myTimer:Timer = new Timer(1000, nCount);
timer_txt.text = nCount.toString();
myTimer.addEventListener(TimerEvent.TIMER, countdown);
function countdown(e:TimerEvent):void
{
nCount--;
timer_txt.text = nCount.toString();
}
Don't test the movie just yet. We still need to add one more line of code.Step 12
Lastly, let's make sure that we start the timer using the start() method of the Timer class. If we don't start the timer, then we won't see anything happen.
var nCount:Number = 10; var myTimer:Timer = new Timer(1000
, nCount
); timer_txt.text = nCount.toString(); myTimer.start(); myTimer.addEventListener(TimerEvent.TIMER, countdown); function countdown(e:TimerEvent):void { nCount--; timer_txt.text = nCount.toString(); }
Step 13
Test the movie. You should now have a working countdown timer.
0 comments: