Copy link to clipboard
Copied
This is the code I have for a count down timer in days, hours, minutes, and seconds but I would just like a timer that counts up from 0 until what ever number I would like and I would like to be able to control the pace....any ideas?
var targetDate:Date = new Date(2012,3,5,13);
addEventListener(Event.ENTER_FRAME, loop);
function loop(e:Event):void
{
var nowDate:Date = new Date();
var ms:Number = targetDate.getTime() - nowDate.getTime();
var sec:Number = Math.floor(ms/1000);
var min:Number = Math.floor(sec/60);
var hr:Number = Math.floor(min/60);
var day:Number = Math.floor(hr/24);
sec = sec % 60;
min = min % 60;
hr = hr % 24;
daytxt.text = day.toString();
hrtxt.text = (hr < 10) ? "0" + hr.toString() : hr.toString();
mintxt.text = (min < 10) ? "0" + min.toString() : min.toString();
sectxt.text = (sec < 10) ? "0" + sec.toString() : sec.toString();
Copy link to clipboard
Copied
Here's an extremely simple counter that will count up from 0 at a rate of one second. It just uses a Timer object.
import flash.utils.Timer;
import flash.events.TimerEvent;
var upCounter:int = 0;
var myTimer:Timer = new Timer(1000,0);
myTimer.addEventListener("timer", timerHandler);
myTimer.start();
function timerHandler(event:TimerEvent):void
{
trace(upCounter);
upCounter++;
}
Copy link to clipboard
Copied
if I upload that to a website will it count up continuously?
Copy link to clipboard
Copied
Yes. If you want to have it start based on some event, then put the line "myTimer.start();" in a function.
Copy link to clipboard
Copied
Hi,
i'm trying to adapt this code for my count-up timer. i need a counter that ticks up every two seconds.
i pasted the code below into a keyframe in flash. i then put a text field with a zero in it on the stage. when i test the movie, i see a flickering zero.
what am i doing wrong?!
thanks in advance,
thomas
___________________________________________
import flash.utils.Timer;
import flash.events.TimerEvent;
var upCounter:int = 0;
var myTimer:Timer = new Timer(2000,7500);
myTimer.addEventListener("timer", timerHandler);
myTimer.start(1);
function timerHandler(event:TimerEvent):void
{
trace(upCounter);
upCounter++;
}
Copy link to clipboard
Copied
change
myTimer.start(1);
to
myTimer.start();
The start function takes no arguments.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more