If you dont 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
i.e., two variables: seconds and date.
Only seconds matters and only seconds will be accessed in Flash.
In ActionScript 2, when loading variable name/value pairs, it was common to start and end the string with ampersands:
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|
Rating: 10 Votes: 1
|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!|