|
|||||||
| Tutorials:flash:actionscript:digital_clock | ||||
Digital ClockBy Roman Clock–Compatable: MX, MX 2004, Flash 8– 1. Make a movieclip, you can give it whatever name you want. We will call this “digClock”. Create 3 layers. The top layer should stay blank, name it “Digital Codes”. The middle layer will have the numbers on it, name it “Numbers”. The bottum layer is just for a background. You can add more layers later. All layers should be 2 frames long. 2. On the second layer called “Numbers” (middle layer), make another movieclip with 13 keyframes, you can give it whatever name you want. We will call this “clockNums”.
3. Copy and paste the “clockNums” movieclip three (3) times. Place them next to each other so they line up horizontally (left to right). Make the one on the left a bit farther away from the other clip copies.
These clips should all be on the layer named “Numbers”, the middle layer. Also, remember that actionscript is CaSe SeNsItIvE so make sure you wrote it exactly. 4. Now on the top layers go to the Action Panel (F9) and add this code: //This will create a new date
digDate = new Date();
//This makes the hour clip go to the correct frame to display the hour
if (digDate.getHours()<12) {
//This IF statement will sort if it is AM or PM
//Flash hours are displayed as a number from 0-23)
digHour.gotoAndStop(digDate.getHours()+1);
} else {
digHour.gotoAndStop((digDate.getHours()-12)+1);
}
//This makes the ten minute clip go to the correct frame to display the ten minutes place
digTen.gotoAndStop(Math.floor(digDate.getMinutes()/10)+1);
//This makes the minute clip go to the correct frame to display the minute
digMin.gotoAndStop(digDate.getMinutes()-(Math.floor(digDate.getMinutes()/10)*10)+1);
5. You have now completed your own digital clock! You can click HERE to go back. Topic Link Download:
|