lundi 31 mai 2010

repeat loop and timer

We learnt something about order and chaos in the last blog.

But we still got a static image. Flash loading the banana's and that was it.

Now we introduce a timer and get the machine alive!

A timer in Flash scripting is a function which can send "events" at a certain time interval. This event is caught by an eventlistener, just like the events from the keyboard and the mouse.


Here is the download, with the example:
http://www.contrechoc.com/flash/orderANDchaos.zip

The timer has to be declared:

var clickTimer:Timer = new Timer(50); //50 is the milliseconds between the ticks
clickTimer.addEventListener("timer", timerHandler2);

and you have to start it ticking:

clickTimer.start();

you can also stop it:


clickTimer.stop();

then like the keyboard or the mouse, you have to prepare a function catching the events:

function timerHandler2 (event:TimerEvent ) {

readSound("click.mp3");}

Now this plays the tick sound every 50 milliseconds, which is a lot!

Try varying the interval....

In the example images are loaded at the tick of the timer.

The images can come in at an unexpected order because the images are loaded from outside. To get a strict order in arrangement from back to front you need to put the images in movieClips, the boxes you already encountered in earlier examples.

Aucun commentaire:

Enregistrer un commentaire