View Full Version : Flash countdown ticker using serverdate

03-26-2008, 03:46 PM

I am making a countdown ticker that would get the current server date & time and then calculate the remaining time from a target date.

I am using a PHP file to output the current server date & time. Then I use the Flash's loadvars function to get the result and format it as a Date field. However, when I trace for remaining days using targetDate-serverDate, I get NaN as the result.

Any help will be greatly appreciated. Below is the code for my flash script as well as the php script.

Flash code:

onClipEvent (load) {
myVars = new LoadVars();
// call the load method to load my php page
// once vars have been loaded:
myVars.onLoad = function(success) {
if (success) {
for (var prop in this) {
var nowDate:Date = myVars.serverDate;
} else {
trace(" Error loading variables ");
// trace (nowDate);
target_date = new Date(2008, 3, 29, 13, 20, 59);
days = Math.floor((target_date-nowDate)/1000/60/60/24);
trace (days);

PHP Code:

// Set default timezone
//date_default_timezone_set('Asia/Calcutta'); // for PHP5

putenv("TZ=Asia/Calcutta"); // for PHP 4

$now = date("Y, n, j, G, i, s");

print "&serverDate=$now&";

Thanx in advance,