Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Paste Description for Actionscript Frame rate manager

The class dynamically adjusts framerate... kind of counteracting artificial browser frame reduction done by some browsers as well

Actionscript Frame rate manager
Sunday, September 2nd, 2007 at 7:07:16pm UTC 

  1. insert into your document class
  2.  
  3. var frameManager = new frameRateKeeper(24,this);
  4. addChild(frameManager);
  5. // where 24 is the frame rate you want, then insert the following code into a file called frameKeeper.as
  6. package{
  7.    import flash.utils.Timer;
  8.    import flash.display.MovieClip;
  9.    import flash.display.Stage;
  10.    public class frameRateKeeper extends MovieClip{
  11.       var requestedFrameRate = 30;
  12.       var frameTracker = 0;
  13.       var currentFrameRate = 30;
  14.       var stageInstance;
  15.       var secondTimer:Timer = new Timer(1000);
  16.       public function frameRateKeeper(num,sI)
  17.       {
  18.          stageInstance = sI;
  19.          requestedFrameRate = num;
  20.          currentFrameRate = num;
  21.          this.addEventListener("enterFrame",function(){ frameTracker += 1;});
  22.          secondTimer.addEventListener("timer", adjustFrameRate);
  23.          secondTimer.start();
  24.       }
  25.       public function adjustFrameRate(ext)
  26.       {
  27.          var curRate = frameTracker;
  28.          if(curRate > requestedFrameRate)
  29.             {
  30.                currentFrameRate --;
  31.                stage.frameRate = currentFrameRate;
  32.             }
  33.          if((curRate < requestedFrameRate) && (currentFrameRate < 90))
  34.          {
  35.             currentFrameRate += requestedFrameRate - curRate;
  36.             stage.frameRate = currentFrameRate;
  37.          }
  38.          //trace("stage set: " + currentFrameRate);
  39.          //trace("actual: " + curRate);
  40.          frameTracker = 0;
  41.          //stageInstance.frameRateCounter.text = stage.frameRate;
  42.       }
  43.    }
  44. }

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus
worth-right
worth-right
worth-right