Introduction
In this tutorial we are going to make a timer that starts at 00 hours 00 minutes 00 seconds and 00 milliseconds.
We'll make a button for stop and start the timer.
I hope this will go to AS: Main under Specific Effects
The Play/Stop buttons
First make three buttons:
Play - The play button
Pause - The pause button
Reset - The reset button
Don't put any AS in the buttons since the AS will go only in the frame.
For changing the instance names on the play button we'll have to Press CTRL+F3 for the properties bar and there is a little text box which says "instance name".
In that box write instead "playbutton" without quotes of course.
Do the same to the pause and reset buttons but instead in pause button the instance is "pausebutton" and on the reset button the instance name is "reset".
The Text Boxes
This is really simple. Just make a text box. Press CTRL+F3 for the properties and change to dynamic text box instead of static text. Copy/paste the dynamic text box 3 times so you got 4 dynamic text boxes.
Now we will show the variables we'll use in these dynamic text boxes.
Name the first text box "hours". To do this you can't name the text box in instance name as before because then the text box will go nuts. No, instead name it "hours" in the box where it says Var:
Name the second text box (in the same way): "minutes", the third "seconds" and the fourth "milli".
Now we got our text boxes for our timer.
Now for the AS (ActionScript)
Below I will post the only AS you'll need and comment the lines with bold //'s.
Place this AS in the frames AS by pressing F9.
Here is the AS:
_root.pausebutton._visible = 0;
// This will make the pausebutton being unvisible when can't use
function restartTimer() {
hours = "00";
minutes = "00";
seconds = "00";
milli = "00";
buttonPressTime = getTimer()/1000-pauseLength;
pause();
}
// This makes a function where the variables becomes 0. Used for the resetbutton
function pause() {
pauseTime = getTimer()/1000;
timing = false;
}
// This makes a function that makes the variable timing false making the timer to pause
function unpause() {
unpauseTime = getTimer()/1000;
pauseLength = (unpauseTime-pauseTime)+pauseLength;
timing = true;
}
/*This makes a function making the timing true and checking what the timer was when paused. Used for the play button. */
_root.onEnterFrame = function() {
totalTime = getTimer()/1000-pauseLength;
goTime = totalTime-buttonPressTime;
//Makes a onClipEvent(enterFrame) function
if (timing) {
hours = Math.floor(goTime/3600);
minutes = Math.floor((goTime/3600-hours)*60);
seconds = Math.floor(((goTime/3600-hours)*60-minutes
)*60);
milli = Math.floor((gotime-(seconds+(minutes*60)+(
hours*3600)))*100);
if (seconds<10) {
seconds = "0"+seconds;
}
if (minutes<10) {
minutes = "0"+minutes;
}
if (hours<10) {
hours = "0"+hours;
}
if (milli<10) {
milli = "0"+milli;
}
}
};
/* This function basicly do so the timer will actually go up and makes the minute go up when the second timer is 60 etc */
playbutton.onRelease=function() {
unpause();
pausebutton._visible = 1;
playbutton._visible = 0;
}
/* Makes the timer go up when the play button is pressed. Also makes the pause button visible and play button invisible. Uses the function unpause */
pausebutton.onRelease=function() {
pause();
playbutton._visible = 1;
pausebutton._visible = 0;
}
//The opposite of the playbutton with the pause button
reset.onRelease= function() {
restartTimer();
pausebutton._visible = 0;
playbutton._visible = 1;
}
/* Makes the pause button invisble and the play button visible. Also uses the function restartTimer*/
//guywithhiscomp