View Full Version : The ticker countdown
koushikgattu
05-29-2008, 06:32 PM
Hi,
How could i increase a number with respect to the time?
For example ..the number should increase by certain amount per second.
Can this be possible with the flash or action script?
Can any one help me out.
Thank you.
KKG
ddadmin
05-29-2008, 07:12 PM
Are you asking about a Flash code in general that does the above?
koushikgattu
05-29-2008, 07:20 PM
yes.By using action script(I have no idea abt it).
Medyman
05-29-2008, 08:12 PM
You're just trying to increase the value of a text field by a certain amount every second? Easy enough...
First step up a dynamic text field on your stage. Let's give it an instance name of "theNumber". Enter whatever starting number you wish. That's all that you'll have to do on the stage. The rest is all actionscript.
Here is the final code. I'll break it down below.
function countdown() {
theNumber.text = theNumber.text - 1;
}
setInterval(countdown, 1000);
The workhorse function is called countdown. Basically it takes whatever is in the text field (theNumber.text) and then subtracts one from it every time it is run. The setInterval() method runs the countdown function every 1000 milliseconds (or every second).
Thus, you have your countdown. If you're trying to do a full time countdown, it gets a little more complicated. Here (http://img177.imageshack.us/my.php?image=timerxa0.swf) is an example of what it will look like in the end. You'll need separate dynamic text fields for each unit. In this example, I've given then an instance name of days, hours, minutes, etc... The ActionScript goes a little like this:
function countdown() {
if(milliseconds.text == 00) {
milliseconds.text = 60;
seconds.text = seconds.text -1;
}
if(seconds.text < 0) {
seconds.text = 59;
minutes.text = minutes.text - 1;
}
if(minutes.text < 0) {
minutes.text = 59;
hours.text = hours.text -1;
}
if(hours.text < 0) {
hours.text = 23;
days.text = days.text -1;
if(days.text < 10) {
days.text = "0" + days.text;
}
}
milliseconds.text = milliseconds.text - 1;
}
setInterval(countdown, 1);
Note: This isn't necessarily the most robust way of doing things, but it illustrates the technique. For the above to work, you'll have to set a framerate at approx. 10fps .
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.