home *** CD-ROM | disk | FTP | other *** search
/ Computer Active 2010 August / CA08.iso / Multimedija / shufflr.air / ShufflrClient.swf / scripts / org / ascollada / utils / FPS.as
Encoding:
Text File  |  2010-06-23  |  2.1 KB  |  76 lines

  1. package org.ascollada.utils
  2. {
  3.    import flash.display.Shape;
  4.    import flash.display.Sprite;
  5.    import flash.events.Event;
  6.    import flash.text.TextField;
  7.    import flash.text.TextFormat;
  8.    import flash.utils.getTimer;
  9.    
  10.    public class FPS extends Sprite
  11.    {
  12.       public var secondTime:Number;
  13.       
  14.       public var frames:Number = 0;
  15.       
  16.       public var prevFrameTime:Number = getTimer();
  17.       
  18.       public var frameTime:Number;
  19.       
  20.       public var time:Number;
  21.       
  22.       public var fps:String = "...";
  23.       
  24.       public var anim:String = "";
  25.       
  26.       public var bar:Shape;
  27.       
  28.       public var tf:TextField;
  29.       
  30.       public var prevSecondTime:Number = getTimer();
  31.       
  32.       public function FPS()
  33.       {
  34.          super();
  35.          this.bar = new Shape();
  36.          addChild(this.bar);
  37.          this.bar.x = 19;
  38.          this.bar.y = 4;
  39.          this.bar.graphics.beginFill(16711680,0.5);
  40.          this.bar.graphics.lineStyle();
  41.          this.bar.graphics.drawRect(0,0,1,15);
  42.          this.bar.graphics.endFill();
  43.          this.tf = new TextField();
  44.          addChild(this.tf);
  45.          this.tf.x = 20;
  46.          this.tf.y = 5;
  47.          this.tf.width = 300;
  48.          this.tf.height = 500;
  49.          this.tf.defaultTextFormat = new TextFormat("Arial",9,16777215);
  50.          this.tf.alpha = 0.6;
  51.          addEventListener(Event.ENTER_FRAME,this.enterFrameHandler);
  52.       }
  53.       
  54.       private function enterFrameHandler(param1:Event) : void
  55.       {
  56.          this.time = getTimer();
  57.          this.frameTime = this.time - this.prevFrameTime;
  58.          this.secondTime = this.time - this.prevSecondTime;
  59.          if(this.secondTime >= 1000)
  60.          {
  61.             this.fps = this.frames.toString();
  62.             this.frames = 0;
  63.             this.prevSecondTime = this.time;
  64.          }
  65.          else
  66.          {
  67.             ++this.frames;
  68.          }
  69.          this.bar.scaleX = this.frameTime;
  70.          this.prevFrameTime = this.time;
  71.          this.tf.text = this.fps + " FPS / " + this.frameTime + " MS" + this.anim;
  72.       }
  73.    }
  74. }
  75.  
  76.