ForumsProgramming ForumTimed!

6 2950
mystera
offline
mystera
39 posts
Nomad

Hey. You know in John's games there are times that count how long you play for? How do you do that in AS2? I just want it to count how many seconds you played for. Thanks in advance.

  • 6 Replies
Fighterlegend
offline
Fighterlegend
44 posts
Nomad

It's not that hard.

It's just some properties..


Like:

var seconds:Number;
var minutes:Number;
var hours:Number;

if(seconds>60){
seconds = 0;
minutes += 1;
}else{
seconds++;
}
if(minutes>60){
minutes = 0;
hours += 1;
}


Something like that..

Just have them as text fields, and plug it in!


If you need anymore help with AS, just contact me!


-Figtherlegend

mystera
offline
mystera
39 posts
Nomad

Thanks. I don't need minutes and hours...I'll just keep it all in seconds.

mystera
offline
mystera
39 posts
Nomad

If I wanted to make a simple timer that counts how long you played for, and then at the end it shows how long you played for. How do you make that?

waynaul
offline
waynaul
73 posts
Nomad

There is a function 'getTimer()' in the flash.utils package that can tell you how many milliseconds have elapsed since the start of the program. I think this function is also in Actionscript 2, but I'm not 100% positive on that.

http://livedocs.adobe.com/flex/3/langref/flash/utils/package.html#getTimer()

John
offline
John
344 posts
Nomad

I think a step counter is the easiest way to think about it.

var seconds:Number = 0;
var frameR:Number = 30; //or whatever
var frameCounter:Number = 0;

onEnterFrame = function() {
frameCounter++;
if(frameCounter == frameR) {
frameCounter = 0;
seconds++;
trace(seconds);
}
}

dank
offline
dank
983 posts
Peasant

Steps is by far the easiest, but if you looking for accuracy, it won't help much as .swfs never play the exact frame rate as is specified in the .fla. As far as I can remember, there are ways to get exact times, but by the time they return something, they become inaccurate. As long as you're staying above 100ms intervals and precision is not dire, there's no better way to go than just a setp counter as john suggested.

Showing 1-6 of 6