-
Creating a stopwatch?
Hey,
I'd like to create a stopwatch that starts at 00:00 when a play button is pressed, and then stops whenever the stop button is pressed. After the stop button is pressed, I would like the time to be displayed on the next frame, and say something like "You pressed the stop button in x".
Can anyone help me with this?
Also, it would also be greatly appreciated if you made it in an .FLA, as I'm not very good at this sort of stuff.
Also, I'm using flash CS3...so actionscript 2.
-
Senior Member
You can do this without setInterval as noted in your thread tags. Using the "getTimer()" function, you can get the number of milliseconds that have elapsed since the application started.
When the play button is pressed, store the result of getTimer in a global variable. When the stop button is pressed, call the getTimer function again and subtract your stored value from it. This value is the number of milliseconds that elapsed between the play and stop button presses.
Here is an example of the above:
PHP Code:
var bStarted:Boolean = false;
var starttime:Number;
onMouseDown = function():Void
{ if(!bStarted){
bStarted = true;
starttime = getTimer();
}else{
bStarted = false;
trace(getTimer() - starttime);
} }
From there, you can divide by 1000 to get the number of seconds and again by 60 to get the number of minutes.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|