home *** CD-ROM | disk | FTP | other *** search
/ Champak 48 / cdrom_image.iso / Games / alex_trax.swf / scripts / __Packages / com / neodelight / std / Analyzer.as next >
Encoding:
Text File  |  2007-10-01  |  2.5 KB  |  79 lines

  1. class com.neodelight.std.Analyzer
  2. {
  3.    var mc;
  4.    var dt;
  5.    var smoothing;
  6.    var timestamp;
  7.    var counted;
  8.    var avgIntime;
  9.    var sumIntime;
  10.    var anadisplay;
  11.    var timeStampStepIn;
  12.    static var count = 0;
  13.    function Analyzer(smoothing, mode)
  14.    {
  15.       this.mc = _root.createEmptyMovieClip("Analyzer" + com.neodelight.std.Analyzer.count,_root.getNextHighestDepth());
  16.       this.mc.timestamp = getTimer();
  17.       if(isNaN(smoothing))
  18.       {
  19.          smoothing = 0;
  20.       }
  21.       this.mc.smoothing = Math.min(1,Math.max(0,smoothing));
  22.       this.mc.createTextField("my_txt",1,50 + com.neodelight.std.Analyzer.count * 50,0,50,20);
  23.       com.neodelight.std.Analyzer.count = com.neodelight.std.Analyzer.count + 1;
  24.       this.mc.my_txt.multiline = false;
  25.       this.mc.my_txt.wordWrap = false;
  26.       this.mc.my_txt.type = "dynamic";
  27.       this.mc.my_txt.variable = "anadisplay";
  28.       this.mc.my_txt.selectable = false;
  29.       this.mc.my_txt.border = true;
  30.       this.mc.my_txt.background = true;
  31.       this.mc.counted = 0;
  32.       this.mc.dt = 30;
  33.       this.mc.avgIntime = 0;
  34.       this.mc.sumIntime = 0;
  35.       var _loc0_ = null;
  36.       if((_loc0_ = mode) !== 1)
  37.       {
  38.          this.mc.onEnterFrame = function()
  39.          {
  40.             var _loc2_ = getTimer();
  41.             this.dt = (1 - this.smoothing) * (_loc2_ - this.timestamp) + this.smoothing * this.dt;
  42.             this.timestamp = _loc2_;
  43.             if(!this.counted)
  44.             {
  45.                return undefined;
  46.             }
  47.             this.avgIntime = this.smoothing * this.avgIntime + (1 - this.smoothing) * this.sumIntime;
  48.             this.sumIntime = 0;
  49.             this.counted = 0;
  50.             this.anadisplay = "%" + Math.round(this.avgIntime / this.dt * 100 * 10) * 0.1;
  51.          };
  52.       }
  53.       else
  54.       {
  55.          this.mc.onEnterFrame = function()
  56.          {
  57.             if(!this.counted)
  58.             {
  59.                return undefined;
  60.             }
  61.             this.sumIntime /= this.counted;
  62.             this.avgIntime = this.smoothing * this.avgIntime + (1 - this.smoothing) * this.sumIntime;
  63.             this.sumIntime = 0;
  64.             this.anadisplay = Math.round(this.avgIntime / this.dt * 100 * 100) * 0.01 + "X" + this.counted;
  65.             this.counted = 0;
  66.          };
  67.       }
  68.    }
  69.    function startCount()
  70.    {
  71.       this.timeStampStepIn = getTimer();
  72.    }
  73.    function stopCount()
  74.    {
  75.       this.mc.sumIntime += getTimer() - this.timeStampStepIn;
  76.       this.mc.counted = this.mc.counted + 1;
  77.    }
  78. }
  79.