package{
Import Flash.display.Sprite
Import Flash.utils.Timer;
Import flash.events.Event;
Import flash.events.TimerEvent;
Import Flash.text.TextField;
public class Fpsshow extends sprite{
private Var Txt:textfield;
private Var count:int=0
Public Function Fpsshow () {
Init ()
}
Private Function init () {
Txt=new TextField ()//Create text instance
txt.textcolor=0xff0000;//Set Text color
AddChild (TXT)//load this text
var mytimer:timer = new Timer (1000);//timer class is very good, similar to setinterval, the parameter is the cycle interval, the unit is milliseconds
Mytimer.addeventlistener ("Timer", Timerhandler)//Registration Event
This.addeventlistener ("Enterframe", Counthandler)/registration event, here is equivalent to 2.0 of the Onenterframe
Mytimer.start ();//timer instance requires start to start
}
Private Function Timerhandler (event:timerevent) {//timer instance invocation method
txt.text= "FPS:" +count
count=0//every 1 seconds to clear zero
}
Private Function Counthandler (event:event) {//True circular call method
count++//Numerical Accumulator
}
}
}