Answers Search Help
Boston University home page
 
    Basics
 
 
 
 
 
 
 
    Interface
 
 
 
 
 
    Concepts
 
 
 
    Animation
 
 
 
 
 
    Buttons
 
 
 
    Publishing
 
 
    Also See
   
   

Attaching Actions to Buttons

Once you've created a button, you probably want it to do something when someone clicks on it with a mouse. To accomplish this, you can add one or more actions to the button.

As described in the section Controlling the Movie, an action is a statement that instructs a movie to do something while it is playing. In the example in Controlling the Movie, the Stop() action was used to prevent a movie from looping. However, as a result, the movie would play one time and then stop, and to play it again the user had to refresh the page. Actions attached to buttons allow you to give users much greater control of the movie.

To make a button interactive in a movie, you place an instance of the button symbol on the Stage and assign actions to the instance. Note that the actions must be assigned to the instance of the button in the movie, not to frames in the button's timeline.

Follow these steps to add a Play button to a movie:

Step 1

Open a new file and create a simple motion tween on the first layer. Create a layer called actions, and in this layer add a Stop action to a blank keyframe in the first frame and a gotoAndPlay(1) action to a blank keyframe in the last frame. If you're not sure how to create a tween, a Stop action, or gotoAndPlay action(1), review the steps in Motion Tween and Controlling the Movie.

Step 2

Create a new layer, name it button, and make it the active layer.

Step 3

Drag a button object from a Library to the stage. Note: if you don't have any buttons in your Library, follow the steps in the Button Frames section to create one, or you can use one from Flash's Common Libraries.

Be careful that your button layer is active - if you drag the button to the same layer that contains your motion tween, your motion tween will no longer work- you will see a dotted line in its layer's timeline rather than an arrow. To fix the problem, delete the button, create a new layer and make it active, then drag the button from the Library again.

By default, the button is in the first frame of the movie. You can control where it appears by dragging the keyframe that contains it along the timeline.

Step 4

Select the button, then double-click Play in the Actions panel to associate with the Play action with this button.

Step 5

Test the movie by selecting Control |Test Movie from the menu. If the button doesn't seem to work, make sure that buttons are enabled by selecting Control | Enable Simple Buttons from the menu.

It should behave like this

WebCentral Using Publishing Learning Training Consulting WebCentral
Answers Search Help
NIS  |  OIT  |  Boston University  |   October 24, 2002