The Use of Time in Flash
Flash uses several techniques to measure the passage of time in projects. The following are the most common strategies:Date class.
A prebuilt class in Flash, useful for interactivity that depends on dates, days, months, and years.getTimer().
A special Flash function useful for measuring the passage of time in milliseconds.Frames.
Representing divisions of time as they relate to animation, sounds, and other interactivity on timelines. Frames provide the most common way of measuring the passage of time in Flash. The movement of one frame to the next (or previous) frame represents the movement of time in a project, either forward or backward. As the timeline moves forward, a progression of events occursa streaming sound plays, for example, or a character moves across the stage.
After you understand these elements, you'll be able to make your projects do the following:Play forward or backward, depending on user interactionReact based on the current date, time, or frame numberDisplay percentage-based information and download status
There's also a special ActionScript toolsetInterval()that allows a function to be called at a regular specified interval (measured in milliseconds). Consider the following example:
The first three lines of the script define the function that will be used. Next, the setInterval() action is set up to call the rotateClip() function every 1.5 seconds (1,000 milliseconds equals 1 second).If you want to pass arguments to the called function, simply add them to the setInterval() action:
function rotateClip() {
myMovieClip_mc._rotation += 10;
}
setInterval(rotateClip, 1500);
A setInterval() action can be turned on and off by assigning a variable name, as in the following example:
setInterval (updateMessageFunction, 20000, "Hello", arg2, arg3)
This example assigns the name myInterval to the setInterval() action. To remove the functionality of the setInterval() action, use the following syntax:
var myInterval:Object = setInterval(rotateClip, 1500);
Using the syntax shown, you can initiate the setInterval() action at any time, calling any function.
clearInterval(myInterval);
• Table of ContentsMacromedia® Flash MX 2004 ActionScript: Training from the SourceBy
Derek Franklin, Jobe Makar Publisher: Peachpit PressPub Date: November 19, 2003ISBN: 0-321-21343-2Pages: 636
Sure, you can use Flash MX 2004 without being a master programmer, but as any Flash developer worth his or her salt will tell you, you''''re not tapping all of its power unless you''''re taking advantage of its scripting language "ActionScript 2.0" which offers a more robust programming model and better object-oriented programming support than ever before. Here to take the fear factor out of learning it are Flash veterans and best-selling authors Derek Franklin and Jobe Makar, who demonstrate that scripting is an instinctual process you already know by translating real-life activities into ActionScript scripts. In these pages, you''''ll find methodologies and techniques for building over 40 real-life Flash ActionScript projects, including sample games, applications, Web sites, and more. New in this edition are coverage of ActionScript 2.0, Web services, Components, Printing, Video, and more. On the companion CD, you''''ll find all the project files and images you need to complete each project.