package com.cet.debug {
//_________________________________________________________
// importz
import flash.display.*;
import flash.events.*;
import flash.system.*;
import flash.text.*;
import flash.utils.*;
//_________________________________________________________
// class
public class fps extends Sprite {
//_________________________________________________________
// private varz
private var holder :Sprite;
private var theBar :Sprite;
private var theBG :Sprite;
private var label :TextField;
private var time :Number;
private var frameTime :Number;
private var prevFrameTime :Number;
private var secondTime :Number;
private var prevSecondTime :Number;
private var frames :Number;
private var theFPS :String;
private var memory :String;
private var other :String;
private var which :String;
//_________________________________________________________
// public varz
public static var BYTES :String = "b";
public static var KILOBYTES :String = "kb";
public static var MEGABYTES :String = "mb";
//_________________________________________________________
// constructor
public function fps(barcolor:uint = 0x006600, baralpha:Number = 1, bgcolor:uint = 0x000000, bgalpha:Number = 1, textcolor:uint = 0xFFFFFF, memorydisplay:String = "kb", maxwidth:Number = 800) {
holder = new Sprite();
theBG = new Sprite();
theBG.graphics.beginFill(bgcolor, bgalpha);
theBG.graphics.drawRect(0, 0, maxwidth, 10);
theBG.graphics.endFill();
holder.addChild(theBG);
theBar = new Sprite();
theBar.graphics.beginFill(barcolor, baralpha);
theBar.graphics.drawRect(0, 0, 25, 10);
theBar.graphics.endFill();
holder.addChild(theBar);
label = new TextField();
label.autoSize=TextFieldAutoSize.LEFT;
label.htmlText = "xero.nu";
label.textColor=textcolor;
label.selectable=false;
holder.addChild(label);
holder.scaleX = 1.5;
holder.scaleY = 1.5;
this.addChild(holder);
this.scaleX = this.scaleY = 2;
which = memorydisplay;
frames = 0;
theFPS = "...";
other = "";
prevFrameTime = getTimer();
prevSecondTime = getTimer();
this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
//_________________________________________________________
// loop
public function onEnterFrame(e:Event):void {
time = getTimer();
frameTime = time - prevFrameTime;
secondTime = time - prevSecondTime;
if(secondTime >= 1000){
theFPS = frames.toString();
frames = 0;
prevSecondTime = time;
} else {
frames++;
}
switch(which) {
case "b":
memory = flash.system.System.totalMemory.toFixed(0) + " bytes";
break;
case "kb":
memory = (flash.system.System.totalMemory / 1000).toFixed(0) + " kbs";
break;
case "mb":
memory = (flash.system.System.totalMemory / 1000000).toFixed(0) + " mbs";
break;
}
prevFrameTime = time;
label.htmlText = " < ( xero.nu ) framerate: "+ theFPS +" fps / "+ frameTime +"ms . memory: "+ memory +" . "+ other.toString() +" >";
theBar.scaleX = theBar.scaleX - ((theBar.scaleX - (frameTime/10)) / 5);
}
//_________________________________________________________
// setter
public function update(x:String):void {
other = x;
}
}
}