Thursday, July 28, 2011

Timer


import flash.utils.Timer;

//TIMER EVENTS
//You have one handler for every listener.

//The enter frame event is based on the frame rate of the movie.
//Timer event is not connected to the rate of the movie, it is based on time.

//Start by creating an instance of our timer and store it in a variable.
var theTimer:Timer = new Timer(50);  //Timer class takes 2 parameters.
 //delay, repeat count (optional)
 //If you don't include the count the default is 0. 0= forever.
theTimer.start();

//event listeners
theTimer.addEventListener(TimerEvent.TIMER, onTimer); //onTimer is the name of the event listener

// event handlers
function onTimer(event:TimerEvent):void {  //inside the parenthesis is the variable that passes the event handler.
 //.TimerEvent is the data class (we use the same as above)
trace("timer");
//myRectangle01_mc.x +=10; //moves it every second to the right
hourHand01_mc.rotation +=360/(60*60*12);
minuteHand01_mc.rotation +=360/(60*60);
secondHand01_mc.rotation +=360/60;  // = 6 degrees

}



No comments:

Post a Comment