Animation

  1. Home
  2. Computing & Technology
  3. Animation

Flash Digital Clock

By Adrien-Luc Sanders, About.com

7 of 10

I’ve created a new variable named clocktime, and told Flash that clocktime is equal to the fetched value of the system time’s hours, minutes, and seconds, separated by a colon:

onClipEvent (enterFrame) {
myclock=new Date() ;
clocktime = ((myclock.getHours())+ ":" + (myclock.getMinutes()) + ":" + (myclock.getSeconds())) ;
}

This is very similar to what we did with the date in the Basic Date Functions lesson. getHours( ) retrieves the hours in 24-hour time (values from 0 to 24) ; getMinutes( ) retrieves the current minutes; getSeconds( ) retrieves the current seconds. All of this is based on the system time on the current user’s computer. For instance, as I was testing this, the clock that I viewed said 21:32 (9:32 p.m.) ; at the same time I IMed the URL to the exact same SWF file to a friend in Lancaster, UK, and his read 3:35 (as he’s six hours ahead of me, and apparently his computer’s a few minutes off).

Using + ties everything together into a single string, and placing the colons inside quotations (“:”) tells Flash to display them as actual text rather than reading them as operators/code.

Explore Animation

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

Animation

  1. Home
  2. Computing & Technology
  3. Animation
  4. Flash Animation Tutorials
  5. Flash Digital Clock

©2009 About.com, a part of The New York Times Company.

All rights reserved.