Advertisement |
Step 6
In the script pane of the Actions panel, create a number variable. Let's initialize it with a value of 10.
Step 7
Assign the nCount variable to the text property of the timer_txt text field.
Step 8
Test your movie. You should see the number displayed in the text field.
Step 9
Go back to the code, and this time, create a Timer object with a delay of 1000. And for the repeatCountparameter, let's pass the nCount variable. The delay is the first value we pass to the Timer() constructor. The repeatCount is the second value that we pass.
Step 10
Now let's create an event listener function for the TimerEvent.TIMER event. This event gets dispatched at a rate that depends on the delay that was specified. Since we specified a delay of 1000 milliseconds, then this means that the event listener function will get called every 1 second. Let's name this event listener function as countdown.
In the script pane of the Actions panel, create a number variable. Let's initialize it with a value of 10.
var nCount:Number = 10;
This will be our countdown number. We will be subtracting 1 from this number every 1 second in order to create the countdown effect.Step 7
Assign the nCount variable to the text property of the timer_txt text field.
var nCount:Number = 10;
timer_txt.text = nCount.toString();
This will display the number in the text field. We have to use the toString() method so that the number gets converted into a string. It needs to be converted into a string so that it can be displayed as text.Step 8
Test your movie. You should see the number displayed in the text field.
Step 9
Go back to the code, and this time, create a Timer object with a delay of 1000. And for the repeatCountparameter, let's pass the nCount variable. The delay is the first value we pass to the Timer() constructor. The repeatCount is the second value that we pass.
var nCount:Number = 10;
var myTimer:Timer = new Timer(1000, nCount);
timer_txt.text = nCount.toString();
This creates a new Timer object named myTimer with a delay of 1000. The 1000 stands for 1000 milliseconds. This means that the timer will count every 1000 milliseconds (or 1 second). For the repeatCount, it's going to have the same value as the initial value of nCount. Since our nCount variable has a value of 10 when we pass it to the repeatCount parameter, then repeatCount will also be 10. This means that our timer will count 10 times and then stop.Step 10
Now let's create an event listener function for the TimerEvent.TIMER event. This event gets dispatched at a rate that depends on the delay that was specified. Since we specified a delay of 1000 milliseconds, then this means that the event listener function will get called every 1 second. Let's name this event listener function as countdown.
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
{
}
0 comments: