<< Chapter < Page Chapter >> Page >

The average frame rate

This project computes and displays the average frame rate for each of five consecutive sets of 200 frames. (The project also shows how to set the frame rate to something other than the default value.)

Figure 1 shows the text output produced by a single run of this project in debug mode on a Windows Vista system.

Default frame rate for flash player 10.

1271890629505 1271890636155 200 30.0751879699248121271890642822 400 29.99850007499625 1271890649487 600 30.0075018754688651271890656153 800 30.003000300030006 1271890662823 1000 29.98500749625187
Default frame rate for Flash Player 10.

The elapsed time

The values in the leftmost column show the elapsed time in milliseconds since Jan 1, 1970 (known in programming circles as the epoch) at the beginning of the run and at every 200th frame event thereafter.

The frame count and the frame rate

The values in the middle column show the frame count.

The values in the rightmost column show the frame rate computed from the amount of time required to display each set of 200 frames.

The default frame rate

This run was made without executing code to set the frame rate to a specific value. The values in the rightmost column in Figure 1 show the default framerate for Flash Player 10 running on a Windows Vista machine. As you can see, the average frame rate is pretty solid at 30 frames per second.

Change the frame rate

Figure 2 shows the project output obtained by removing the comment markers and enabling the following statement in Listing 16.

stage.frameRate = 10;

The purpose of this statement is to set the frame rate for the Flash Player to ten frames per second.

Measured frame rate of flash player 10 at ten frames per second.

1271891012974 1271891033098 200 9.9383820314052861271891053097 400 10.00050002500125 1271891073097 600 101271891093097 800 10 1271891113096 1000 10.00050002500125
Measured frame rate of Flash Player 10 at ten frames per second.

The average frame rate

As you can see in Figure 2, the average frame rate in this case is solid at ten frames per second.

A best-case scenario

This is probably the optimum case for measuring the frame rate since the program doesn't do anything else that may have an adverse impact on the abilityof the Flash Player to maintain a constant frame rate.

Won't explain the code at this time

I'm not going to explain the code in Listing 16 at this time. You should have no difficulty understanding most of the code in Listing 16. Some of the code inListing 16 is new to this lesson, but I will explain very similar code later inthe lesson in conjunction with other projects.

Listen for TIMER events fired by a Timer object

Constructing a Timer object

The flash.utils package contains a class named Timer . An object instantiated from this class will fire a TIMER event every (specified value) milliseconds.

The constructor for the class requires two parameters:

  1. The delay until the first event and between successive events in milliseconds as type Number .
  2. The repeat count as type int , which specifies the number of events that will be fired. If this value if 0, the timer will fireevents indefinitely.

The reciprocal of the rate

Note that whereas the frequency of frame events is specified as frames per second , the repetition parameter for timer events is specified as the time interval between events (milliseconds per event) . One is the reciprocal of the other.

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




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?

Ask