First time here? First time here? Newsletter Signup Newsletter
651326 Members and growing! | Flash Jobs
Search tutorials
Author: Nuno Mira | Website: http://www.nunomira.com/

PHP

If you don’t have access to a PHP enabled server you can easily install one locally.
WampServer and XAMPP are the most common ones. You will get Apache, PHP and MySQL and with this a whole new world of possibilities.

PHP offers several date related functions. As you're interested in the number of milliseconds after 0:00:00 GMT January 1, 1970, time() seems like the perfect choice. Unfortunately, this doesn't really serve our purpose, as the value returned by time() is relative to 0:00:00 GMT January 1, 1970 which means it is independent from the server's timezone.
You'll have to use some math here as well, to take the server's timezone into account.
Also note that this value is in seconds and not milliseconds, which is the unit that Flash requires.

The date() function returns a string with the value formatted according to the values passed to it. When the second parameter is ignored, the current time is used.
For example, date('YmdHis') returns a very useful string such as 20110228142400. which can be looked at as: yyyymmddhhmmss.

The parameter Z (see the documentation) will return exactly what you need - the timezone offset in seconds - date('Z').
After converting the string returned by date('Z') to an integer using strtotime(), you're ready to go:

$offset =  strtotime (date('Z') );
$seconds = time() + $offset;
echo "seconds=" . $seconds;

You may also output the server time to help you debug and make sure that every thing's fine.

$offset =  strtotime (date('Z') );
$seconds = time() + $offset;
echo "seconds=" . $seconds;
echo "&date=" . date('YmdHis');

If you open server-time.php directly in your browser you'll see something like

seconds=1298905373&date=20110228150253

i.e., two variables: seconds and date.
Only seconds matters and only seconds will be accessed in Flash.

Attention:

In ActionScript 2, when loading variable name/value pairs, it was common to start and end the string with ampersands:

&seconds=1298905373&date=20110228150253&

In ActionScript 3 this will create an error so, make sure that you only use the ampersand (&) to separate the variable name/value pairs:

Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.
	at Error$/throwError()
	at flash.net::URLVariables/decode()
	at flash.net::URLVariables()
	at flash.net::URLLoader/onComplete()
» 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!

Comments

  • 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.