View Full Version : [AS2] Time zone from ComboBox?

02-20-2009, 04:49 PM
Hey all,

I'm trying to create a clock that allows the user to select a time zone from a combobox and have the correct time show up on a clock in the next frame. Right now I have this actionscript for the combobox:

timeZone = myLocation.selectedItem;

myLocation.dataProvider = [
{label:"Select a City", data:0},
{label:"Dallas", data:6},
{label:"Los Angeles", data:8} ];

var oListener:Object = new Object();
oListener.change = function(oEvent:Object):Void{

myLocation.addEventListener("change", oListener);

and the code on the clock frame looks like:

time=new Date(); // time object
seconds = time.getUTCSeconds()
minutes = time.getUTCMinutes()
hours = time.getUTCHours()

hours = hours +(minutes/60);
hours = hours -timeZone;

seconds = seconds*6; // calculating seconds
minutes = minutes*6; // calculating minutes
hours = hours*30; // calculating hours

sec._rotation=seconds; // giving rotation property
min._rotation=minutes; // giving rotation property
hour._rotation=hours; // giving rotation property

But for some reason the clock is not pulling the variable "timeZone" and always shows the hour hand at its default position (12). For example, the data for "Los Angeles" is 8. If I put "8" in the place of "timeZone" it works, but "timeZone" does not. Why??

02-20-2009, 04:58 PM
I think you need to put this line timeZone = myLocation.selectedItem; in this function oListener.change = function(oEvent:Object):Void{
so that it is setting it = to the variable once it has been selected.

02-20-2009, 05:01 PM
Hmm...the code now looks like:

oListener.change = function(oEvent:Object):Void{
timeZone = myLocation.selectedItem;

...Same problem. :/

02-20-2009, 05:09 PM
Should I have any code on the submit button to pull the variable into the next frame? Right now it's just a go to and play....

02-20-2009, 06:35 PM
ok. first I guess I didn't read your original post. I didn't realize you had this on multiple frames, I also didn't realize you had a submit button. If you set the variable whenever they click on something, then whenever they hit submit the timezone variable should still be stored. I also thing hours = hours -timeZone; probably won't work right now, because you need to pass in the data. So in order for that to work I think you need to say timeZone = myLocation.selectedItem.data; instead of timeZone = myLocation.selectedItem;

02-20-2009, 07:23 PM
Worked like a charm. Thank you so much. :)