Analog Stop Watch: The Hands
myMinuteHandmySecondHand
The registration point (centre of the symbol) is at the bottom of the hands. This is important, otherwise they will not rotate correctly.
![]()
My second hand with registration point at base.
Place the two clock hands on the clock face in the correct position:
The clock is now assembled.
Open the Button Library (F11) and place three buttons on the Main Stage:
Everything is now ready for the ActionScript.
Analog Stop Watch: The ActionScript
Place the following ActionScript in Frame 1:
myMinute = 0;
myTimer = setInterval(wait, 1000);function wait() {
mySeconds++;
_root.mySecondHand._rotation += 6;
_root.myMinuteHand._rotation += .1;
if (mySeconds == 60) {
myMinute++;
mySeconds = 0;
}
if (mySeconds<10) {
myZero = 0;
} else {
myZero = "";
}
}
Analog Stop Watch: The ActionScript Explained
There are two lines which different from the script in the previous example. One controls the movement of the second hand and the other the movement of the minute hand.
_root.mySecondHand._rotation += 6;
This moves the second hand 6°
This moves the second hand 6°
I get to that by 360° in a circle divided by 60 seconds equals 6° movement every second: 360°/60 = 6°
There are 3600 seconds in an hour so if you do a similar equation for the minute hand: 360°/3600 = 0.1°
_root.myMinuteHand._rotation += .1;
This moves the minute hand 0.1°
This moves the minute hand 0.1°
Analog Stop Watch: The Stop Button ActionScript
on (release) {
clearInterval(myTimer);
}
Stops the setInterval from running, which means the function 'wait' is no longer called so the actions contained within that function also stop. In this case the hands on the stop watch and digital display stop moving.
Analog Stop Watch: The Reset Button ActionScript
on (release) {
_root.mySeconds = 0;
_root.myMinute = 0;
_root.myZero = 0;
_root.myMinuteHand._rotation = 0;
_root.mySecondHand._rotation = 0;
clearInterval(myTimer);
}
_root.mySeconds = 0;
Resets the variable mySeconds to zero.
Resets the variable mySeconds to zero.
_root.myMinute = 0;
Resets the variable myMinute to zero.
Resets the variable myMinute to zero.
_root.myZero = 0;
Resets the variable myZero to zero.
Resets the variable myZero to zero.
_root.mySecondHand._rotation = 0;
Resets the Second hand to the up-right vertical position.
Resets the Second hand to the up-right vertical position.
_root.myMinuteHand._rotation = 0;
Resets the minute hand to the up-right vertical position.
Resets the minute hand to the up-right vertical position.
clearInterval(myTimer);
Stops the clock. If you don't do this and you press the Reset button when the stop watch is running the hands would go back to zero and then start to move again.
Stops the clock. If you don't do this and you press the Reset button when the stop watch is running the hands would go back to zero and then start to move again.
Analog Stop Watch: The Go Button ActionScript
on (release) {
clearInterval(myTimer);
myTimer = setInterval(wait, 1000);
}
clearInterval(myTimer);
Stops the clock! You might well ask why? If the setInterval is running and then tell setInterval to run again it will run twice simultaneously! This will mean that the clock speed would go too fast: Two ticks per second! Imagine if you click the go button ten times. That's right the second hand will go around the clock face every 6 seconds!! Not much good as a timer!
Stops the clock! You might well ask why? If the setInterval is running and then tell setInterval to run again it will run twice simultaneously! This will mean that the clock speed would go too fast: Two ticks per second! Imagine if you click the go button ten times. That's right the second hand will go around the clock face every 6 seconds!! Not much good as a timer!
myTimer = setInterval(wait, 1000);
Starts the setInterval so the goes again.
Starts the setInterval so the goes again.
Your stop watch should now be ticking nicely at one tick per second.
This stop watch would not need very much additions to become a normal analog clock. All it would need is the hour hand and to know what the time is. Flash can get the time from the local clock on the computer it is running on or from a sever - but that's nothing to do with setInterval, so I am not going to go there.