Flash Animation 11: ActionScripting to Link Your Buttons And Scenes

of 06

Introduction and Review

To start this lesson off, you should be back in the first scene of your animation, on the very last frame where you created your button options. Before starting this lesson you should have all of your scenes complete: your primary scene with your introductory animation ending in your buttons, and a separate scene (two or more) to correspond with each of your button options. If you haven't done this already, you should have stops on the end of each of your scenes. Otherwise after we complete this lesson your animation will work incorrectly and will play more than just your chosen options.

This lesson will be purely Actionscripting, using the on (release) and gotoaAndPlay commands in conjunction with each other to make your buttons play the scenes that match them.

of 06

Assigning an Action to an Object

Instead of assigning an action to a frame, we're going to assign an action to an object--in this case, our button. Just to be on the safe side I distributed my buttons to separate layers, but it's not entirely necessary.

To assign an action to an individual button, unlock the layer that it's on, select it, and then right-click and select Actions. Your Actions panel will open; it may already have expanded to a particular subset based on what Flash thinks you want to do. Ignore it, minimize that subset, and move on to the next step.

of 06

Accessing the "On" Commands

You'll notice in the top of your Actions panel, there'll be a dropdown that displays "Actions for [insance name] (button name)", letting you know that everything you're doing right now operates on that specific object and nothing else. You can pull down the dropdown to select other objects in your scene to assign actions to. For now, though, stick with your first button.

In the left-hand window, with your hierarchy of commands, you'll expand the first group (Actions) and then below that, expand Movie Controls. The main command that we're interested in here is the on command; this command, combined with parameters, defines the behavior of an object in response to mouse actions. Double-click the on command to insert it in the actions for this button.

You'll see the information above the actionscripting display window change to reflect the options for the on command, defining which mouse action will cause the button to respond. By default it inserts an on (release); this is the most common, because it mimics the typical mouse action of web browsing where a link is activated not when we click on it, but when we relax our fingers to release that click. If you used press instead of release, then action would take place the moment you clicked, without waiting for release.

We'll leave it on release, because that's all we need now. You can find the others here.

of 06

Accessing the "Goto" Commands

Notice that when you first insert your on (release) command, the command is followed by an opening bracket {, and then on the next line, a closing bracket }. The space between these two brackets is where we tell our movie what it's suppose to do when that on (release) command is followed. As of now we've told it to do nothing, so there's nothing there. We're going to tell it to go to the scene associated with the button and play it, using the gotoandplay command.

To do this we'll need to access the main root of this command, the goto command--which is right above the on command in our expanded menu on the left. To insert this command, you'll highlight the line that contains your on (release) command, and then double-click on goto.

Now the options to customize the command will change to display the options for goto--letting you define if you'll use a gotoAndPlay, or gotoAndStop before setting the Scene that you'll go to on this action, the type of increment/definer, and then the number/label of that increment/definition. Go to and Play is the default, and since that's what we want to do, we'll leave it at that.

In your scripting window, there should be a command that says gotoAndPlay (1) ;. With the current settings, because Flash by default uses the current scene when inserting a new command, this would rewind the movie to Frame 1 and start it over again.

of 06

Setting Your gotoAndPlay Properties

All that's left to do is set the correct scene. On the Scene dropdown, click to expand; you can use simple options like <current scene>, <next scene>, and <previous scene>, but those are rather non-specific and can create issues if you start moving scenes around in a complex movie. Instead we're going to select a scene name; I named my two extra scenes with my options, to make them easier to find. For this one, since I'm using the blue button, I'm using the scene labeled Blue Option.

When you click on the scene, it will update your code to reflect it; you can leave the "Type" alone, as we want it to go to a particular frame in our scene--that is we, want it to start from the beginning, so we want to leave the type as Frame Number and the Frame as 1 so that it goes to frame 1 in the scene Blue Option and begins to play. (If this is a little confusing, look at it this way: the Type option tells Flash what kind of information is going inside the parentheses to provide parameters for the gotoAndPlay command, while the value that follows--in this case a number for Frame--is the actual value for the parameter itself.)

of 06

Breakdown of the ActionScript Code and Conclusion

There's now a new value in the code--the name of the scene, in quotes and separated from the frame number by a comma. (You'll also see a semicolon ( ; ) at the end of the line of code; this is standard to show an end to the command line and is necessary for Flash to know that this is where the command stops.) Let's break this down into parts:

on (release) {} : tells Flash which action is going to trigger the commands that follow inside the brackets ( {} ) ; in this case, the release of a mouse click on the button.
gotoAndPlay () : tells Flash what action to perform after the trigger of a released click--it's going to go to something and play it.
"Blue Option" : tells Flash where it's going to perform the "play" part of the gotoAndPlay command. It's almost like a map that says "turn left at this street". Don’t' forget that it's separated by a comma from other parameters so that Flash knows to read them as separate things.
1 : tells Flash what frame number to start on when it gets to "Blue Option". If "Blue Option" says "turn left at this street", then "1" is the street address of the place on that street where you're going.

And you've just created a clickable button that actually plays something when you perform an action. You'll need to repeat his for your other options to complete the project. You can see my end result here.

mla apa chicago
Your Citation
Sanders, Adrien-Luc. "Flash Animation 11: ActionScripting to Link Your Buttons And Scenes." ThoughtCo, Feb. 15, 2016, thoughtco.com/flash-actionscripting-to-link-buttons-scenes-140695. Sanders, Adrien-Luc. (2016, February 15). Flash Animation 11: ActionScripting to Link Your Buttons And Scenes. Retrieved from https://www.thoughtco.com/flash-actionscripting-to-link-buttons-scenes-140695 Sanders, Adrien-Luc. "Flash Animation 11: ActionScripting to Link Your Buttons And Scenes." ThoughtCo. https://www.thoughtco.com/flash-actionscripting-to-link-buttons-scenes-140695 (accessed November 18, 2017).