THE USE OF TIME IN FLASH


Flash uses several methods to measure the passage of time in projects. The following are the most common:

  • Date object. A pre-built object in Flash useful for interactivity that is dependent on dates, days, months, and years.

  • getTimer() function. This special Flash function is 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) one represents the movement of time in your project, either forward or backward. As the timeline moves forward, a progression of events occurs a streaming sound plays, for example, or a character moves across the stage.

Once you understand these elements, you'll be able to make your projects do the following:

  • Play forward or backward, depending on user interaction

  • React based on the current date, time, or frame number

  • Display percentage-based information and download status

  • More

There's also a special ActionScript tool setInterval() that allows a function to be called at a regular specified interval (measured in milliseconds). To understand this, take a look at the following:

 function rotateClip() {    myMovieClip._rotation += 10;  }  setInterval (rotateClip, 1500); 

The first three lines of the above script define the function that will be used. Next, the setInterval() action is set up to call the rotateClip() function every 1.5 seconds (1000 equals 1 second).

If you wish to pass arguments to the called function, simply add them to the setInterval() action, as follows:

 setInterval (updateMessageFunction, 20000, "Hello", arg2, arg3) 

A setInterval() action can be turned on and off by assigning it a variable name, as in the following example:

 myVariable = setInterval(rotateClip, 1500); 

This will assign the name myVariable to the setVariable() action. To remove the functionality of the setVariable() action, you would use the following syntax:

 delete myVariable; 

The setInterval() action can be initiated any time, calling any function using the syntax shown. (In the next lesson, you'll learn how you can use this action to create a rotating banner ad system.)



Macromedia Flash MX ActionScripting Advanced. Training from the Source
Macromedia Flash MX ActionScripting: Advanced Training from the Source
ISBN: 0201770229
EAN: 2147483647
Year: 2002
Pages: 161

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net