How to Play Reverse Frames Flash on AS3

Use AS3 code to flashback frames in reverse.

Reversing frames with Flash ActionScript 3 (AS3) code comes in handy when creating Flash movies. For example, by reversing the frame sequence for a sunset animation you can quickly create a sunrise, eliminating the need to create a sunrise animation from scratch. There is no reverse frame command in AS3. As a result, playing frames in reverse with AS3 requires that you write AS3 code that will force the animation to start at the last frame and step one frame back every time a frame event occurs.

Start the Flash program and select "Flash File(ActionScript 3.0)" from the splash screen to allow AS3 code to be used to build your movie.

Click the "Timeline" option from the "Window" menu to display the timeline. Press the "F6" key on your keyboard to insert a keyframe on the timeline. Continually press the "F6" key until 30 keyframes have been inserted on the timeline. Tiny circles will be placed in each frame to signify that the frame is a blank keyframe.

Position your mouse cursor over "Frame 1" in the timeline and click your left mouse button to select it. Press the "R" key on your keyboard to activate the rectangle drawing tool. Position your mouse cursor over the stage, then click and drag your mouse to draw a rectangle. Release the left mouse button to set the size of the rectangle. Click "Frame 2" on the timeline and draw another rectangle, but at a different position on the stage. Continue drawing rectangles on each frame in different positions until you have reached frame 20.

Position your mouse cursor over "Frame 1," then click your left mouse button to select Frame 1. Press the "F9" key on your keyboard to open the Actions editor and write the reverse frames AS3 code in Frame 1.

Position your mouse cursor on the first line of the Actions editor. Click your mouse button and type in the code below. This will instruct Flash to go to the end of the movie (frame 30) and display the frame preceding the last frame displayed (starting at 30) every time a new frame is displayed (at the frame rate in frames per second specified in the "fps" text box in the Timeline panel).


addEventListener(Event.ENTER_FRAME, reverse); function reverse(reverseevent:Event):void { prevFrame(); }

Mark Stansberry has been a technical and business writer over for 15 years. He has been published in leading technical and business publications such as "Red Herring," "EDN" and "BCC Research." His present writing focus is on computer applications programming, graphic design automation, 3D linear perspective and fractal technology. Stansberry has a Bachelor of Science in electrical engineering from San Jose State University.