1. Computing

Flash Digital Clock


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.

©2014 About.com. All rights reserved.