Tuesday, November 30, 2010

Digital Clock in Flash

In this tutorial we will learn how to create a digital clock in Flash. So Lets start


Step 1 : Insert three layers in timeline window and rename them.



Step 2 : Select Frame1 of bg layer, Design the framework for digital clock. Select frame2 and press F5 .





Step 3 : Select text tool from your tool box, go to Frame1 of text layer and insert Dynamic text field in work area.  Select frame2 and press F5, Name this Dynamic text field instance as "clock_txt"





Step 4 : Go to frame1 of action layer.Press F9 Key to open the action panel, copy and paste the below mentioned script in the action panel

time=new Date(); // time object
var seconds = time.getSeconds()
var minutes = time.getMinutes()
var hours = time.getHours()
if (hours<12) {
ampm = "AM";
}
else{
ampm = "PM";
}
while(hours >12){
hours = hours - 12;
}
if(hours<10)
{
hours = "0" + hours;
}
if(minutes<10)
{
minutes = "0" + minutes;
}
if(seconds<10)
{
seconds = "0" + seconds;
}
clock_txt.text = hours + ":" + minutes + ":" + seconds +" "+ ampm;


Step 5
: Go to frame2 of action layer and press F6 to insert a new keyframe. Still keeping the play head on the frame2, go to action panel and copy paste the below mentioned script.
 


gotoAndPlay(1);


We have finished the clock now Press Ctrl+Enter to view your clock

This is Final Result .



Hope you enjoy. Take Care.

Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home