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.
- Skill level:
Other People Are Reading
Things you need
- Adobe Flash Professional: CS3, CS4 or CS5 Versions
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).
Tips and warnings
- Although reversing frames with ENTER_FRAME is effective, the Yoyo method of the Tween class will also reverse the motion sequence of an object if the original forward motion was also applied with a Tween object and method. See "Republic of Code; Tween Class in Flash ActionScript" listed in the Resources section for further details.
- If you have written ActionScript code in different frames in your Flash movie you will have to write the AS3 code to reverse the frames with that code in mind. And that's because when you step the frames backwards, the code in the frames will also be executed in reverse order.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for
- Adobe Systems; ActionScript 3.0 Language and Components Reference; Event; June 2008
- Adobe Systems; ActionScript® 3.0 Reference for the Adobe® Flash® Platform; Event; April 2011
- Adobe Systems; ActionScript® 3.0 Reference for the Adobe® Flash® Platform; MovieClip; April 2011
- Swami Charan; Using the Tween Class in Flash
- Republic of Code; Tween Class in Flash ActionScript