Latest tutorial: Making a Movieclip face another Movieclip or point on the stage | Ask Tutorial5!
 

Get tutorials on EMail




Adobe Flash 8 Digital Clock using ActionScript

(27 votes)
Written by AnaS   

inco5.gifTime is money is a well-known saying. This tutorial explains how to make a Flash 8 Digital clock using ActionScript programming.
Start Adobe Flash 8 and create a new document having 250x70 dimensions.


Draw a text field on the stage using the Text tool from the Tools panel.
In the Properties Inspector set the following for the text field:
W:230; H:50; X:10; Y:10; also set the formatting, I choose Verdana, size 40, bold, color #990000, centered.
Don’t forget to select Dynamic Text and to give it the instance name clock_txt like in the picture below:

clock1.jpg

Insert a new layer and name it actions. Select the first frame of the actions layer, press F9 to open the Actions panel and put there the following code in (attention: ActionScript is case sensitive):

this.onEnterFrame = function(){
var time:Date = new Date();
var hour = time.getHours();
var minute = time.getMinutes();
var second = time.getSeconds();
var clock:String=new String();

//format the way the time is displayed

if(hour > 12){
hour-=12;
}
if(hour < 10){
hour = "0"+hour;
}
if(minute < 10){
minute = "0"+minute;
}
if(second <10){
second = "0"+second;
}

//now create the time

clock = hour+":"+minute+":"+second;
clock_txt.text=clock;
}

Now test the movie (CTRL+Enter) and see the result:

You need to Register in order to download the FLA file.



Subscribe now via RSS feed and get all the new tutorials

written by Cynthia , September 11, 2007

My computers internal clock is way behind of what it should be, and I was wondering if you knew how to get it so you can set your own time out of flash. I have it set to take the time off my own computers clock, but I cannot fix it. Thank you.
written by Can't , November 22, 2007

do i select a different frame for each script? plus the second two contain errors.
written by Maria Barekou , May 27, 2008

How to create five minutes clock;I dont want to show the hours but the time of 5 minutes if you understand. Please answer it's a matter of life and death.I have to finish a project.
written by parthu , March 04, 2009

i am unable to display the clock Even after following ur code
written by vikram jeet , March 19, 2009

tell me exact scripting its not clear to me...
plz m frustrared..
written by DJDonaL3000 , April 08, 2009

Excellent!
written by Remi , May 10, 2009

this.onEnterFrame = function(){
var time:Date = new Date();
var hour = time.getHours();
var minute = time.getMinutes();
var second = time.getSeconds();
var clock:String=new String();
if(hour > 12){
hour-=12;
}
if(hour < 10){
hour = "0" hour;
}
if(minute < 10){
minute = "0" minute;
}
if(second
written by TJ , September 12, 2009

How do you get the time to keep ticking? I get mine to display the time once, but it does not update? Please help! Thanks!
written by pankaj chawada , October 06, 2009

sir how to add a uas time in india
written by pankaj chawada , October 06, 2009

sir how to add a USA time in India
written by dede , January 05, 2010

ME TOO ------> i am unable to display the clock Even after following ur code
written by syam leneesh M.S , January 27, 2010

i am unable to display the clock Even after following ur code
written by ghd , July 26, 2010

tell me exact scripting its not clear to me...
plz m frustrared..

Do you need more help? Ask now!
 

busy
Last Updated ( Saturday, 22 March 2008 )