Quick Tip: Change the Frame Rate at Runtime Using ActionScript 3
Dive into this Quick Tip and discover how to change the Frame Rate of your movie, while it's running…
Final Result Preview
Let's take a look at the final result we will be working towards:
Step 1: Brief Overview
We'll make use of a Slider component to modify the stage framerate
property and display a MovieClip to see the changes.
Step 2: Set Up Your Flash File
Launch Flash and create a new Flash Document, set the stage size to 400x200px and the frame rate to 25fps.
Step 3: Interface
This is the interface we'll be using, it includes a Slider Component and a MovieClip taken from my Apple Preloader tutorial.
You'll also notice some static text below the slider indicating the minimum and maximum FPS.
Step 4: Slider
Open the Components Panel (Cmd+F7) and drag the Slider component from the User Interface folder, align it to the center in the stage and click the Properties Panel to edit its parameters.
Use the data from the image above and prepare for some ActionScript 3…
Step 5: ActionScript
Create a new ActionScript Class (Cmd+N), save the file as Main.as and start writing:
package { import flash.display.Sprite; import fl.events.SliderEvent; public class Main extends Sprite { public function Main():void { //Listen for slider movement slider.addEventListener(SliderEvent.CHANGE, changeFPS); } private function changeFPS(e:SliderEvent):void { //Change the frame rate using the slider value stage.frameRate = e.value; } } }
Step 6: Document Class
Remember to add the class name to the Class field in the Publish section of the Properties panel.
Conclusion
Try the demo and experiment with the uses of this feature!
I hope you liked this Quick Tip, thank you for reading!