Flash Digital Clock
How to display digital time with Flash
In this tutorial you will learn how to display digital time using actionscript in Flash. You will learn about the date object, how to write functions and call them using time delay in actionscript.
You Are Here ::: Home >> Free Tutorials >> Flash Tutorials >> Digital Clock
Follow the steps below:
Digital Time using Actionscript in Flash
- The Date class in Actionscript along with its various methods helps us to retrieve date and time values (Local / GMT).
- Create three Dynamic Textboxes for displaying the hours, minutes, seconds and name their variables as ch, cm, cs respectively.
- Write the following Actionscript code in the Actions window (F9) as given below:
- Variables dt, timeint Flash are first declared using the keyword 'var' and any function can be defined by using the keyword 'function' followed by a function-name and the function code which can be written within the {...} as shown above.
- The constructor new Date() is used create an instance of the Date object and assigned to the variable 'dt'.
- The methods getHours, getMinutes, getSeconds of the Date object are used to retrieve the hours, minutes, seconds and assigned to the 3 Dynamic Textbox variables.
- Save your work and test the Movie (Ctrl + Enter). That's it you have learnt how to create scrolling textboxes in Flash using Actionscript.
var dt, timeint;
dt = new Date();
ch = dt.getHours();
cm = dt.getMinutes();
cs = dt.getSeconds();
timeint=setInterval(timer,1000);
function timer() {
dt = new Date();
ch = dt.getHours();
cm = dt.getMinutes();
cs = dt.getSeconds();
}
Note: GMT time can also be displayed in a similar manner by using the getUTCHours(), getUTCMinutes(), getUTCSeconds() methods of the Date object.
Software Required
Compatible Versions of Flash for this Tutorial
Flash CS5 Professional | Flash CS4 Professional
Note: For uses of lower versions of Flash some visual interface images would differ.
Recommended Version: Adobe Flash CS5 Professional