Timer Events

 

The Timer Events work similar to the Mouse Event, only this time instead of listening for a particular mouse event, the listening Timer Event will observe a Time related function.

The great advantage of developing with ActionScript is that with small variations to the ActionScript we can make big changes to our application during runtime.

The Timer Event can be used in a number of different ways. In the most basic form, the Timer Event can begin to track time from a certain point in time to another point in time. By default, the Timer Event would run forever if not programmed to stop or react when a particular time related condition is met.

Having a Timer Event that would simply track time forever may sound cool, but does not serve a real function. To make the Timer useful, it needs to be able to do more than just track. The Timer Event will track time in any type of format you wish, and can be programmed to create events are different times. A Timer Event can even turn itself off.

Tutorial 1 – Timer Event

With the ActionScript Panel open add the following code to the first frame.

Timer Event Running Forever

Testing the movie shows the Timer Event in action, with the output panel generating the word “Tock” every second.

Before adding more functionality to the code, I want to first review some of the more important elements of the code.

Beginning on line 1

Big changes can happen inside parentheses. Any type of parameters can be calculated and processed within parentheses. The Timer Event is no exception. The closing parentheses in this case on line 1 represent the time. For the Timer Event time is tracked in milliseconds.

  • 1000 milliseconds equal one second (line 1)
  • Call back functions can be anything you like (timerClock line 2&4)
  • Timer need to be started with the .start function (line3)

Unlike the Mouse Event, Setting up the Timer Event to run is only the first part of the requirement. The Timer Event has to also be instructed to Start.

Tutorial 2 – Timer Event to Precise time

02_AS_Timer_002

By changing the time information within the parentheses, you can alter or modify how the time is sorted, deal or distributed.

Timer Event - Control Speed & How many times

With a function, command executed every 1000’s of a millisecond = Output is every second.

  • (1000) = 1 second
  • (2000) = 2 seconds
  • (500) = ½ second
  • (250) = ¼ second

With ActionScript, we can alter the math within the parentheses to alter the outcome. By adding a comma after the time interval we can instruct the Timer Event how many times to run  the Timer before completing.

  • (1000,5) = 1 second for five times
  • (2000,2) = 2 seconds for two times
  • (500,4) = ½ second for four times
  • (250,10) = ¼ second for ten times

Tutorial 3 – Timer Complete

02_AS_Timer_003

Tracing the Timer Event is great. Controlling the speed of playback and how many times the Timer Event will repeat is useful. Now, we want to take the programming a little deeper. I want ActionScript to listen for when the Timer Event has completed. I do not really care what type of time related equation is happening in the new Timer parentheses; those sums are already processed prior to the for this Complete function to is activated.

At the point of completion, I want the Timer Complete Listener to capture the Timer Events

Timer Event Complete

Tutorial to Creating a Clock using the Timer Event

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© 2011 Irish Guy Suffusion theme by Sayontan Sinha