An accurate stopwatch
i've been having problems creating accurate stopwatch. tried using 2 different timers still having problems milliseconds. , i'm having problem resetting stopwatch too. wanted return 0 when reset stopped. need help. here's code:
var mytimer:timer = new timer(1000);
var mymillitimer:timer = new timer(1);
mymillitimer.addeventlistener(timerevent.timer, domillitimer);
mytimer.addeventlistener(timerevent.timer, dotimer);
var mytimenum = 0 ;
var mymillinum = 0;
function domillitimer (e){
mymillinum++;
mymillinum = math.floor(mymillinum%10)
mymillisectxt.text = mymillinum;
}
function dotimer (e:timerevent):void{
mytimenum++;
var mysec = math.floor(mytimenum%60);
var mymin = math.floor(mytimenum/60%60);
var myhour = math.floor(mytimenum/3600);
if (mysec<10){
mysectxt.text = "0"+mysec;
}else {
mysectxt.text = mysec;
}
if (mymin<10){
mymintxt.text = "0"+mymin;
}else {
mymintxt.text = mymin;
}
if (myhour<10) {
myhourtxt.text = "0"+myhour;
} else {
myhourtxt.text = myhour;
}
}
btnstart.addeventlistener(mouseevent.click, dostart);
function dostart (e) {
mytimer.start();
mymillitimer.start();
}
btnstop.addeventlistener(mouseevent.click, dostop);
function dostop (e) {
mytimer.stop();
}
btnreset.addeventlistener(mouseevent.click, doreset);
function doreset (e) {
mytimer.reset();
mymillitimer.reset();
}
only gettimer() returns accurate time.
More discussions in ActionScript 3
adobe
Comments
Post a Comment