<< Chapter < Page Chapter >> Page >

The TIMER event handler

The TIMER event handler is shown in Listing 15. Except for the method signature, this is essentially the same code that you saw in the ENTER_FRAME event handler in Listing 4.

The timer event handler.

public function onTimer(event:TimerEvent):void { x += dx;y += dy; }//end onTimer

That's a wrap

I'm going to let that be it for this lesson, which has concentrated on time bases and animation for ActionScript 3 projects.

Run the projects

I encourage you to run these projects from the web. Then copy the code from Listing 16 through Listing 21. Use that code tocreate your own projects. Compile and run the projects. Experiment with the code, making changes, and observing the results of your changes. Makecertain that you can explain why your changes behave as they do.


I will publish a list containing links to ActionScript resources as a separate document. Search for ActionScriptResources in the Connexions search box.

Complete project listings

Complete listings of the projects discussed in this lesson are provided below.

The main class for the project named timebase01.

/*Project TimeBase01 The purpose of this project is to experiment with the useof Event.ENTER_FRAME as a time base. The project computes and displays the average frame rate over five consecutivesets of 200 frames. It also shows how to set the frame rate to something other than the default value.Must be run in debug mode to display the text data. *********************************************************/package { import flash.display.Sprite;import flash.events.Event;public class Main extends Sprite{ private var sprite:Sprite;private var date:Date; private var countA:uint = 0;private var baseTime:Number = 0; private var currentTime:Number = 0;public function Main():void {sprite = new Sprite(); addEventListener(Event.ENTER_FRAME, onEnterFrame);// stage.frameRate = 10; }//end constructor//--------------------------------------------------////Event handler. public function onEnterFrame(event:Event):void {currentTime = new Date().time; if (countA == 0) {baseTime = currentTime; trace(baseTime);}//end ifif ((countA>0)&&(countA<1001)&&(countA % 200 == 0)){ trace(currentTime + " " + countA + " "+ 1000 / ((currentTime - baseTime) / 200)); baseTime = currentTime;}//end if countA++;}//end onEnterFrame }//end class}//end package

The main class for the project named timebase02.

/*Project TimeBase02 The purpose of this program is to experiment with the useof a Timer object as a time base. The program computes and displays the average tick rate of the Timer objectover five consecutive sets of 100 frames . It also shows how to set the tick rate to a specific value and how tospecify the number of ticks. *********************************************************/package { import flash.display.Sprite;import flash.events.TimerEvent; import flash.utils.Timer;public class Main extends Sprite{private var sprite:Sprite; private var timer:Timer = new Timer(1000/10,1001);private var date:Date; private var countB:uint = 0;private var baseTime:Number = 0; private var currentTime:Number = 0;public function Main():void {sprite = new Sprite(); timer.addEventListener(TimerEvent.TIMER, onTimer);timer.start();// stage.frameRate = 10; }//end constructor//--------------------------------------------------// //Event handlerpublic function onTimer(event:TimerEvent):void { currentTime = new Date().time;if (countB == 0) { baseTime = currentTime;trace(baseTime); }//end ifif((countB>0)&&(countB<1001)&&(countB % 200 == 0)){trace(currentTime + " " + countB + " " + 1000 / ((currentTime - baseTime) / 200));baseTime = currentTime; }//end ifcountB++; }//end onTimer//--------------------------------------------------// }//end class}//end package

Questions & Answers

how do I set up the problem?
Harshika Reply
what is a solution set?
find the subring of gaussian integers?
hello, I am happy to help!
Shirley Reply
please can go further on polynomials quadratic
hi mam
I need quadratic equation link to Alpa Beta
Abdullahi Reply
find the value of 2x=32
Felix Reply
divide by 2 on each side of the equal sign to solve for x
Want to review on complex number 1.What are complex number 2.How to solve complex number problems.
yes i wantt to review
use the y -intercept and slope to sketch the graph of the equation y=6x
Only Reply
how do we prove the quadratic formular
Seidu Reply
please help me prove quadratic formula
hello, if you have a question about Algebra 2. I may be able to help. I am an Algebra 2 Teacher
Shirley Reply
thank you help me with how to prove the quadratic equation
may God blessed u for that. Please I want u to help me in sets.
what is math number
Tric Reply
x-2y+3z=-3 2x-y+z=7 -x+3y-z=6
Sidiki Reply
can you teacch how to solve that🙏
Solve for the first variable in one of the equations, then substitute the result into the other equation. Point For: (6111,4111,−411)(6111,4111,-411) Equation Form: x=6111,y=4111,z=−411x=6111,y=4111,z=-411
x=61/11 y=41/11 z=−4/11 x=61/11 y=41/11 z=-4/11
Need help solving this problem (2/7)^-2
Simone Reply
what is the coefficient of -4×
Mehri Reply
the operation * is x * y =x + y/ 1+(x × y) show if the operation is commutative if x × y is not equal to -1
Alfred Reply
An investment account was opened with an initial deposit of $9,600 and earns 7.4% interest, compounded continuously. How much will the account be worth after 15 years?
Kala Reply
lim x to infinity e^1-e^-1/log(1+x)
given eccentricity and a point find the equiation
Moses Reply
A soccer field is a rectangle 130 meters wide and 110 meters long. The coach asks players to run from one corner to the other corner diagonally across. What is that distance, to the nearest tenths place.
Kimberly Reply
Jeannette has $5 and $10 bills in her wallet. The number of fives is three more than six times the number of tens. Let t represent the number of tens. Write an expression for the number of fives.
August Reply
What is the expressiin for seven less than four times the number of nickels
Leonardo Reply
How do i figure this problem out.
how do you translate this in Algebraic Expressions
linda Reply
why surface tension is zero at critical temperature
I think if critical temperature denote high temperature then a liquid stats boils that time the water stats to evaporate so some moles of h2o to up and due to high temp the bonding break they have low density so it can be a reason
Need to simplify the expresin. 3/7 (x+y)-1/7 (x-1)=
Crystal Reply
. After 3 months on a diet, Lisa had lost 12% of her original weight. She lost 21 pounds. What was Lisa's original weight?
Chris Reply
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!

Source:  OpenStax, Object-oriented programming (oop) with actionscript. OpenStax CNX. Jun 04, 2010 Download for free at http://cnx.org/content/col11202/1.19
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with actionscript' conversation and receive update notifications?