Simple one but useful.
[as3]new FPSMeter(this, 10, 10);[/as3]
gives you a numeric readout of the current calculated frames per second.
Demo time:
[kml_flashembed publishmethod=“static” fversion=“10.0.0″ movie=“http://www.bit-101.com/blog/wp-content/uploads/2009/08/FPSDemo.swf” width=“400″ height=“400″ targetclass=“flashmovie”]
[/kml_flashembed]
Here’s the code for that demo:
[as3]package
{
import com.bit101.components.*;
import flash.display.Sprite;
import flash.events.Event;
[SWF(backgroundColor=0xeeeeee, width=400, height=400)]
public class Playground extends Sprite
{
private var running:Boolean;
public function Playground()
{
new FPSMeter(this, 10, 10);
new PushButton(this, 10, 30, “Draw”, onClick);
new PushButton(this, 10, 55, “Clear”, onClear);
}
protected function onClick(event:Event):void
{
running = !running;
if(running)
{
event.target.label = “Stop”;
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
else
{
event.target.label = “Draw”;
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
}
}
protected function onClear(event:Event):void
{
graphics.clear();
graphics.lineStyle(0, 0, .1);
}
protected function onEnterFrame(event:Event):void
{
graphics.lineStyle(0, 0, 0.1);
graphics.lineTo(Math.random() * 400, Math.random() * 400);
}
}
}[/as3]
Just draws random lines, which will eventually start to bog down the CPU and affect the frame rate. Clearing or stopping the drawing will bring it back up to 24.
A few notables: