Buttons in Flash using ActionScript 3.0: Going to next frame and previous frame

Some people have been asking how to create button code in Flash (CS3, CS4, or CS5) that progresses the playhead in a SWF to the next or previous frame using ActionScript 3.0. This is not too difficult, and is a super simple code modification from any other button in AS3 (and is actually a touch easier than AS2 due to scoping issues).

This post includes an example of how to create two buttons that click between a few different frames. I’ll also include a (CS4) FLA file for you to look at and the AS2 equivalent.

The following code is for two buttons with the instance names button1 and button2. It uses the usual code for multiple buttons in a FLA file (for more information, see this post). A link to an example FLA follows the AS3 code.

button1.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler1);
function mouseDownHandler1(event:MouseEvent):void
button2.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler2);
function mouseDownHandler2(event:MouseEvent):void

Download the FLA file

In ActionScript 2.0, you need to do a bit of targeting to make things work correctly (although the button code is a bit simpler of course). Here’s the same thing in AS2:

button1.onRelease = function() {
button2.onRelease = function() {

(You could use _root instead of this._parent, although it isn’t a recommended practice).

Download the FLA here



Add a Comment

Your email address will not be published. Required fields are marked *

WP-SpamFree by Pole Position Marketing