First time here? First time here? Newsletter Signup Newsletter
651326 Members and growing! | Flash Jobs
Search tutorials
Author: luco | Website: http://www.luco.com.br

[code]

all right! we have the board, we have the pieces. it's definitely time to make them... move. (thunder sound fill) put an instance of the clock on the stage and name it something complex and unreasonably odd like "clock". just for fun. this clock's gotta be a movieclip for this to work, you know. then select the clock and add the following code to it (you should see something like "actions - Movie Clip" on the Actions Pannel):
onClipEvent (enterFrame) {
    // gets the time information and stores in a variable called "now"
    now = new Date();
    // assigns values individually
    h = now.getHours();
    m = now.getMinutes();
    s = now.getSeconds();
    // angle adjust relative to the hours
    setProperty(_root.clock.hrs, _rotation, (h+1)*30);
    // angle adjust relative to the minutes
    setProperty(_root.clock.min, _rotation, m*6);
    // angle adjust relative to the seconds
    setProperty(_root.clock.sec, _rotation, s*6);
}
now for some explanation. let's brake it! uhm, just drop the baseball bat, son.
    onClipEvent (enterFrame) {
this opens up an event to be executed by the clock movieclip. at every second, this script will repeat, creating a nice tick-clock effect!
    now = new Date();
this gets the current time and stores it in a variable called "now" all the time. cus now IS all the time. and the clock hands use this variable to display time correctly all the time! neat, huh?
    h = now.getHours();
    m = now.getMinutes();
    s = now.getSeconds();
now we separate hours from minutes and seconds. very useful ahead.
    setProperty(_root.clock.hrs, _rotation, (h+1)*30);
here we set the angle of the hours hand using the hour provided by New Date() and multiplying it by 30. why 30? divide 360, wich is the number of degrees in a circle (any circle, even if you didn't draw it) by 12, the number of hours in a clock (any clock, even for the Gestalt freaks). and (h+1) will assure you'll never get a zero (cus midnight is displayed as 00:00.)
    setProperty(_root.clock.min, _rotation, m*6);

    setProperty(_root.clock.sec, _rotation, s*6);
these lines have the same function, operating on minutes and seconds. because you get as many minutes in an hour as you get seconds in a minute, the numbers are strictly the same, and they each jump on increments of 6 degrees.
» Level Intermediate

Added: 2003-12-28
Rating: 6 Votes: 21
(10 being the highest)
» Author
Brazillian advertiser-webdesigner hybrid. likz art, heavy, grooved electro-music + Brazillian rythms. plays capoeira. enjoys comedies, but when watches drama cries like a baby. that's it!
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!

Comments

  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: doc_chin7
» Description:

The flash's horizontal road drive was done in CS4 and was upgraded to CS6. The car responds to right/ left key and flash will auto-generate the movement of roads from left-right or right-left based on random number. Have fun driving in this virtual environment and avoid other cars... :) If you are creative, a road driving game can be created from it.

Featured Sound Loops
Image for equalize

Audio Player

» Author: BoxCat
» Title: CPU Talk
» Description: From the cyberpunk RPG, "Nameless: the Hackers" Completely Free to use! Keywords: edm hip hop rap electronic mysterious mission hacking chase exciting spy ios ambient chilling love happy sad angry suspense
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: nathan
» Description:

A recorded sound of the Dimensional Fork Gate.