First time here? First time here? Newsletter Signup Newsletter
Login | Register | 651326 Members and growing!
Search tutorials
Author: Nuno Mira | Website:

Flash Clock with the server's time using PHP

Minimum Flash version:

ActionScript version:

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-02-28
Rating: 3.25 Votes: 4
(10 being the highest)
» 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!


  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: work2survive
» Title: Girl Walking 1kb
» Description: Walking girl, animation just takes 1kb, using high heels shoes, and fashion model attitude.
Featured Sound Loops
Image for equalize

Audio Player

» Author: BoxCat
» Title: CPU Talk
» Description: From the cyberpunk RPG, "Nameless: the Hackers" Completely Free to use! Keywords: edm hip hop rap electronic mysterious mission hacking chase exciting spy ios ambient chilling love happy sad angry suspense
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: nathan
» Description:

A recorded sound of the Dimensional Fork Gate.