Flash Clock with the server's time using PHP
Minimum Flash version:
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|
Rating: 4.33 Votes: 3
|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 the files used in this tutorial.|
|Download (32 kb)|
|More help? Search our boards for quick answers!|