Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
We’ll start off with one of the most-desired features in the evolution of ActionScript: the ability to adjust the frame rate of a file with code. Consider a simple example that switches a SWF’s frame rate between 1 and 24 frames per second, with every click of the mouse. This script can be found in the frame_rate_trace.fla source file.
1 stage.frameRate = 24;
2
3 this.addEventListener(Event.ENTER_FRAME, onEnter, false, 0, true);
4 function onEnter(evt:Event):void {
5 trace(stage.frameRate);
6 }
7
8 stage.addEventListener(MouseEvent.CLICK, onClick, false, 0, true);
9 function onClick(evt:MouseEvent):void {
10 if (stage.frameRate == 24) {
11 stage.frameRate = 1;
12 } else {
13 stage.frameRate = 24;
14 }
15 }