Simple FPS Counter

snipped by Haxd

Simple FPS Counter in AS3

This code block uses MXMLC code hinting. If you want to use it in Flash CS3, remove the package, [SWF] and final } from the code and paste it into Flash.

package {
	import flash.display.*;
	import flash.text.*;
	import flash.events.*;
	import flash.utils.*;
 
	[SWF(width='550', height='400', backgroundColor='#FFFFFF', frameRate='30')]
	public class goMain extends MovieClip {
 
		private var tf:TextField;
		private var oldTimer:uint;
		private var fps:uint;
 
		public function goMain() {
			stage.scaleMode = StageScaleMode.NO_SCALE;
 
			tf = new TextField();
				tf.x = 0;
				tf.y = 0;
				tf.text = 0 + " / " + String(stage["frameRate"]);
				tf.selectable = false;
			addChild(tf);
 
			addEventListener(Event.ENTER_FRAME, goMainLoop);
		}
 
		private function goMainLoop(e:Event):void {
			var newSeconds:uint = int(getTimer()/1000);
			fps++;
			if (oldTimer != newSeconds) {
				tf.text = String(fps) + " / " + String(stage["frameRate"]);
				fps = 0;
			}
			oldTimer = newSeconds;
		}
	}
}