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

frameRateKeeper
Monday, September 24th, 2007 at 8:19:56pm UTC 

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

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