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

Home > Articles

  • Print
  • + Share This
From the author of

Updating in Real Time

With all the supporting functions in place, it's finally time to create the "real-time" clock. The properties of a Date object are static, so you keep them up-to-date by refreshing the object every frame. All the code within the curly brackets of the onClipEvent(enterFrame) section is run every frame, so if you create a new Date object called now within this section, it will constantly be refreshed with the current time.

  1. Insert this code in the onClipEvent(enterFrame) section:

    // Set UTC Date object
    now = new Date();
    nowDate = dateString(now);
    nowTime = timeString(now);

    The first line after the comments creates a new Date object called now. The next two lines pass the now object into your new formatting functions. The variables created by these functions have already been assigned to text fields at the bottom of the map.

  2. Save your ActionScript text file.

  3. Go back to Flash MX. Recompile and test your Flash movie.

    It is important to save the text file because Flash includes this code when it compiles. If all goes well, you should now see the days, hours, and minutes tick over in real time!

  • + Share This
  • 🔖 Save To Your Account