jump to navigation

This is NOT the official website of AvantBiz Consulting Limitd but just some casual discussions about various topics. Please visit www.avantbiz.com if you need our professional services.

ActionScript 3 QuickTip #1: Dynamic Frame Rates December 14, 2006

Posted by eddie in : Computer 電腦,Flash , trackback

ActionScript 3 QuickTip #1: Dynamic Frame Rates

This is a *very* cool new feature in ActionScript 3. We now have the ability to dynamically change the SWF frame rate at runtime using ActionScript. In the example below I have a somewhat creepy clown who is animating from side-to-side on the screen. You can use the slider to change the frame rate from 0 to 800 and something. There are a lot of applications for this such as lowering the frame rate for slower machines dynamically. The AS 3 code from the example is posted below:

  1. this.stage.frameRate = 0;
  2. rate.text = “0 fps”;
  3. thumb.addEventListener(MouseEvent.MOUSE_DOWN, starter);
  4. thumb.addEventListener(MouseEvent.MOUSE_UP, stopper);
  5. thumb.addEventListener(MouseEvent.MOUSE_OUT, stopper);
  6. thumb.addEventListener(MouseEvent.MOUSE_MOVE, mover);
  7. function starter(args:Event)
  8. {
  9.         thumb.startDrag(false, new Rectangle(track.x, thumb.y, track.width, 0));
  10. }
  11. function stopper(args:Event)
  12. {
  13.         thumb.stopDrag();
  14. }
  15. function mover(args:Event)
  16. {
  17.         var dist:Number = (thumb.x – track.x) / (track.width + track.x);
  18.         this.stage.frameRate = Math.round(dist*1000);
  19.         rate.text = Math.round(dist*1000).toString() + ” fps”;
  20. }

Comments»

no comments yet - be the first?