First time here? First time here? Newsletter Signup Newsletter
Search tutorials
Author: Nuno Mira | Website: http://www.nunomira.com/

Flash Clock with the server's time using PHP

Minimum Flash version:

ActionScript version:

Accompanying thread:

Other requirements:
A PHP enabled server

What you'll learn:

You'll learn how to display date and time in Flash, using the Date Class.
You'll also learn how to output the time on the server using PHP, load it into Flash as a variable name/value pair, and display it in the hh:mm:ss format.


You want to show a clock on your website with you current local time. You couldn't do it by using Flash alone, retrieving the time from the user's computer, because that would mean that users in different timezones would see different times. As you want all of them to see the same time - the time on your server - you'll have to grab this value from it.


The Date Class allows you to pass different values to its Constructor to create a specific date. If you pass one value only, this will be the number of milliseconds after 0:00:00 GMT January 1, 1970.
This is the approach you'll follow, as this value is easily retrieved with PHP. This value will be output by PHP and loaded into Flash. Once it finishes loading you are ready to create the date you want.
Unfortunately this is not enough as you'd see the correct time once only. The second after, the time would be wrong already as the clock woudn't be updated with the correct time. Fortunately, with a little of math and the getTimer() method of the flash.utils Package you can circumvent this limitation. You just have to calculate the number of milliseconds that have elapsed since the data finished loading, and add this value to it.

» Level Intermediate

Added: 2011-03-17
Rating: 3.5 Votes: 4
» Author
Nuno Mira has been a Flash Developer for 9 years. He loves teaching, and learning. When he isn't coding he may be surfing or snowboarding.
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!
Featured Flash FLA
» Author: Inocreato
» Title: RaiseTheBlocks
» Description: Raise all the blocks to win the game
Featured Sound Loops
Image for equalize

Audio Player

» Author: TomCat Carty
» Title: The Wood
» Description: Just a little game ending or it can maybe be looped. Recorders with music box and percussion to give the feel of well, I don't know, the woods? Free to use, just credit me. thank you
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: Davisigner
» Description: Hmm... what to say about this one? It's reminiscent of the closing notes of the opening music from the Three Stooges done in a church organ style with a closing cymbal crash. I'll give this one away gratis, but feel free to check out my free loops and potential upcoming license-mandated ones over in the respective part of Flashkit.