Actionscript Analog Clock

Category : Flash Views : 6949
Version : 8 Rating
3.5/5 (28 votes)
Type : Text Source File: actionscript-analog-clock.zip
Result: See the result


Previous | 1 | 2 | Next

That's all; very simple, but accurate:
Free Flash Tutorials, Actionscript, Analog Clock

My clock on the left and the windows clock on the right.

Code Explanation

this.onEnterFrame = function() { var date = new Date();
A Date object has the current time and date of the computer its running.
We need to create one to get the time from it.

var hours = date.getHours();
The function getHours() returns the current hour.

var minutes = date.getMinutes();
getMinutes() returns the minutes.

var seconds = date.getSeconds();
And getSeconds() returns the seconds.

min._rotation = 360 / 60 * minutes;
To get the angle needed just divide the number of minutes that exists (60!) by 360º and multiply by the number of minutes we have now.

hour._rotation = 360 / 12 * hours; sec._rotation = 360 / 60 * seconds; }
The other two angles use the same logic.
Note that the hours uses the 12-hour notation instead of the 24-hour notation.


del.icio.us digg it Reddit Stumble Upon Technorati

Previous | 1 | 2 | Next




Supporters

Reseller Web Hosting