Publishers of technology books, eBooks, and videos for creative people

Home > Articles

  • Print
  • + Share This
From the author of

Updating the Mouse Time Zone

The next batch of code will do for the mouse zone time what the previous batch did for UTC time. The two blocks are almost identical, except for some Date modification that tweaks the Date to compensate for the time zone offset.

  1. Back in your text editor, add this code to the onClipEvent(enterFrame) section:

    // Set Zone Date object
    Mousezone = new Date();
    Mousezone.setMinutes(now.getUTCMinutes() + ( * 60));
    MousezoneDate = dateString(Mousezone);
    MousezoneTime = timeString(Mousezone);

    You'll notice the modification in the third line. Here you take a new Date object called Mousezone and use .setUTCMinutes to add enough time to compensate for the time zone offset. The currently highlighted zone is converted to minutes by multiplying it by 60. It is then added to the current value of UTCMinutes to offset it. Once modified, the new Mousezone Date object can be interrogated as normal.


    This is where the beauty of the Date object finally shows itself. If you try doing any calendar calculations using multiple individual variables, you'll soon go slightly mad. The biggest advantage to Date object mathematics is that it takes care of all the rounding stuff for you. For example, if you add 610 minutes to a Date, it knows to add 10 hours and 10 minutes, correct for new days, leap years, and all the other potential pitfalls. It's worth it!

  2. Save your ActionScript text file.

  3. Go back to Flash MX and recompile your Flash movie. Watch this time for the time difference as you pan around the map!

Figure 9Figure 9 Real-time date and time.

  • + Share This
  • 🔖 Save To Your Account