5 Replies Latest reply on Dec 19, 2006 2:32 AM by Newsgroup_User

# Chrono

Hi,
I've done this chrono but it seems that it's not very acurate. Any tip how I could improve it?

Thanks

It starts like this:

var intervalId:Number;
var count:Number = 0;
var duration:Number = 10;
function executeCallback():Void {
count++;
}
intervalId = setInterval(this, "executeCallback", duration);

Then I stop it with this:

clearInterval(intervalId);

And this is to show the result:

txtElapsedTime.text = (count/100)+"sec.";
• ###### 1. Re: Chrono
May i Know why you are dividing by 100 ???
I think , there should be the number of milliseconds in a seconds...
• ###### 2. Re: Chrono
Unless I'm wrong, the result is shown in milliseconds and I divide it by 100 to get it in seconds. But I admit this was a guess... :/
• ###### 3. Re: Chrono
>>Unless I'm wrong, the result is shown in milliseconds and I divide it by
>>100 to get it in seconds.

Centi is 100... milli is 1000 - so you divide by 1000 to get seconds.

--
Dave -
www.blurredistinction.com

• ###### 4. Re: Chrono
So I have to divide by 1000 and not 100. Apart from that, is the rest of the code alright?
• ###### 5. Re: Chrono
> Apart from that, is the rest of the code alright?

Sort of. setInterval is not really the most accurate way of measuring time
in Flash. Try something along these lines

// Start timer
this.nStartTime = getTimer();
// do stuff
// do more stuff
// assess how much time has elapsed in seconds
this.nTimeElapsed = (getTimer() -this.nStartTime)/1000;
--
-------------------------------
Remove '_spamkiller_' to mail
-------------------------------