Categories
Featured jobs
» More ActionScript, Flash and Flex jobs.
» Advertise a job for free
Our network
Advertisement

 »  Home  »  Tutorials  »  Flash  »  Beginner  »  Simple digital clock

Simple digital clock

By Jono Hayward | Published 09/9/2005 | Beginner | Rating:
Jono Hayward
This user is yet to take control of their account and provide a biography. If you are the author of this article, please contact us via support AT actionscript DOT org. 

View all articles by Jono Hayward
Page 1 of 2

Written by: Jono Hayward, www.groove.org.au,
Difficulty Level: Beginner
Requirements: Flash MX 2004 or higher
Assumed Knowledge: Variables

Download FLA

Clock tutorial
This is a pretty simple clock
I find it easiest to put all this in a movie clip, then you can move your clock around the stage wherever you want it. So basically:

step one:

Hit ctrl/apple + f8 to create a new movie clip. Doesn't matter what you call it. Open the library by pressing ctrl/apple + L and drag the clip onto the stage.

step two:
Open the clip by double-clicking it in the library. Right/control click on the second frame of the clip and click "insert frame"*.

step three:
Inside the movie clip make two dynamic text boxes. Give one a variable name of "time" (without the speech marks) and one a variable name of "datefinal".

step four:
Click on the first frame of the movie and open the actions panel. This is where the fun begins.
First we want to get all the values off of the user's system clock and assign them to separate variables.
Copy this code into the actions panel:

mydate = new Date();
seconds = mydate.getSeconds();
minutes = mydate.getMinutes();
hours = mydate.getHours();
day = mydate.getDay();
date = mydate.getDate();
month = mydate.getMonth();
year = mydate.getFullYear();

step five:
How some of these variables, if we just shoot them off to the text box will give some odd results. For example, if it's Sunday the "day" variable will just return "0", if its Monday it will return "1" etc. Same with months. And while a conventional digital clock would display the time as 9:03:05 this would show 9:3:5 which just looks weird. So to fix all this, we use these bits of code:

step five(a):
>>to change the day to its name, we use an if statement.

if (day==0){
        day = "Sunday"
} else if (day==1){
        day = "Monday"
} else if (day==2){
        day = "Tuesday"
} else if (day==3){
        day = "Wednesday"
} else if (day==4){
        day = "Thursday"
} else if (day==5){
        day = "Friday"
} else if (day==6){
        day = "Saturday"
}

What this basically does is say to the program, "if the day is 0 then the day is actually sunday" and so on.

Same concept for months

if (month==0){
        month = "January"
} else if (month==1){
        month = "February"
} else if (month==2){
        month = "March"
} else if (month==3){
        month = "April"
} else if (month==4){
        month = "May"
} else if (month==5){
        month = "June"
} else if (month==6){
        month = "July"
} else if (month==7){
        month = "August"
} else if (month==8){
        month = "September"
} else if (month==9){
        month = "October"
} else if (month==10){
        month = "November"
} else if (month==11){
        month = "December"
}



Spread The Word / Bookmark this content

Clesto Digg it! Reddit Furl del.icio.us Spurl Yahoo!

Related Articles
Comments
  • Comment #1 (Posted by Chris - cbloom at intrado.com)
    Rating
    Neat! The only thing I would add is to use the Switch() statement instead of those multiple if/else statements when finding day and month.
     
  • Comment #2 (Posted by peter - peter.a.martin at hotmail.com)
    Rating
    Nice little script, but details count such as using the var keyword and missing the .text on the text fields could mean the difference between the script working & not working especially when you are saying to copy and paste your code.
     
  • Comment #3 (Posted by Stephanie)
    Rating
    I was a good tutorial but you need to be more specific. I tried making this and I've never done anything before in flash. I got all the scripting right just it was apparently in the wrong spot my teacher fixed it for me anyways you need to tell people that the scripting needs to be within the Clock movie!

     
Submit Comment



Search Entire Site
Add to Google
Advertisements
Article Options
Latest New Articles
Set up a simple IIS Server for Flash
by Peter McBride

Day 1 at FITC Toronto 2008
by Anthony Pace

Simple reflection effect with AS2
by Jean André Mas

ActionScript.org Meets Josh Tynjala (aka dr_zeus)
by ActionScript.org Staff

Rapidly Create Online Flash Movies to Help Users Market, Sell and Support Software and Hardware
by Sabrina F

mailing list
Enter your email address:
mailing list
Subscribe Unsubscribe
© 2000-2007 actionscript.org! All Rights Reserved.
Read our Privacy Statement and Terms of Use...
Our dedicated server is hosted and managed by WebScorpion Webhosting.