Dynamic display of FPS values

Source: Internet
Author: User
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
}

}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.