Link to home
Start Free TrialLog in
Avatar of stan4d
stan4d

asked on

How can I set actionscript 3 timer to read time from server, GMT or UTC rather than local machine?

I am creating a timer to countdown to New Years at Times Square. I found this great tutorial to create a timer but it reads time form the end user's computer so if they are in a different time zone it will give the wrong time.

http://schoolofflash.com/2008/04/tutorial-creating-a-timer-in-actionscript-3/

Is there a way to tell Flash to read from the server's clock or GMT or UTC and then adjust?
Avatar of rascalpants
rascalpants
Flag of United States of America image

you need to pass the year, month, and day into the SWF using FlashVars or an appended query string...


here is what i put in my first frame...


// LoaderInfo example code
var loaderObj:Object = LoaderInfo(this.root.loaderInfo).parameters;

var theYear:int;
var theMonth:int;
var theDay:int;

     
if ( loaderObj.endyear )
{
  theYear = loaderObj.endyear;
  theMonth = loaderObj.endmonth;
  theDay = loaderObj.endday;
}
else
{
  // does not exist, so set manually
  theYear = 2010;
  theMonth = 0;
  theDay = 1;
}


var endDate:Date = new Date( theYear, theMonth, theDay );



then you just need to pass in the three variables...  endyear, endmonth, endday


rp / ZA
btw... I am using Actionscript 3.0

if you need AS 2.0 then instead of using the LoaderInfo class, you can just reference the passed in variable like this...

_root.endyear, _root.endmonth, _root.endday


so you can use this...


var endDate:Date = new Date( _root.endyear, _root.endmonth, _root.endday );


rp / ZA
Avatar of stan4d
stan4d

ASKER

Thanks for the quick reply.

That works to control the end date, but what I'm looking to do is control the timezone that the countdown is relative to. Right now it is getting the time from my computer regardless of what time zone I view it. If I'm not set to New York time on my computer then my countdown is wrong.

In this example I'm focused on 12:00 New York time. So no matter where you view it from I need to show the New York countdown. So the timer will actually reach 00:00 at 12:00am  in New York, 9:00pm in California, 6:00pm in Hawaii, etc...

BTW - need for AS3 - thanks.
ASKER CERTIFIED SOLUTION
Avatar of rascalpants
rascalpants
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of stan4d

ASKER

Sorry - I've been trying to make it work for a while - no success. Is it possible you could please provide a sample showing implenmented getUTCHours? There's got to be something I'm missing. Many thx.
Avatar of stan4d

ASKER

Got it working - thanks for your help!