• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Hour 14. Using ActionScript to Create No... > Task: Add Buttons to Your Animation ...

Task: Add Buttons to Your Animation to Stop and Continue Playback

Either use the file created in the previous exercises or make a new file with a Motion Tween over several frames (make sure you can see something moving while the animation plays).

Insert a new layer for the buttons. We don't want to place buttons in the layer with an animation; that will affect the tween. Name this layer Buttons.

Into the new Buttons layer, draw a rectangle that will become our button. Select it, and then convert to symbol (press F8). Name it MyButton and make sure the behavior is set to Button.

We're going to need two buttons, so either copy and paste the instance already onstage or drag another instance of the MyButton symbol from the Library onto the Stage in the Buttons layer. Apply a Tint color style to each instance—one red (for Stop) and one green (for Play). As you recall, you do so by selecting the Button instance onstage and using the Properties panel to select Tint from the Color Styles drop-down list and then selecting a color and percentage.

Now we need to attach an Action to each button individually. Select the red button and access the Actions panel. From the plus button select Actions, Movie Control, stop to add an Action statement to the Script Area on the right. Notice that even though you tried to add just one Action (stop), you were given three lines. That's because you can't simply put Actions on Button instances—you have to put them inside mouse events. The default event is Release, meaning the Action will execute when the user clicks then releases the button. We'll look at others later, but if you want to explore other events, select the first line in the Script Area and notice the check boxes in the Parameters Area of the Actions window (see Figure 14.7).

Figure 14.7. The stop Action (attached to the button) can't go anywhere except within a mouse event.

Now select the green-tinted Button instance and assign the play Action, found under Actions, Movie Control. Test the movie.

The fact that Actions on Button instances must be contained within a mouse event makes sense because you have to specify precisely when the Action is to be executed, but it's still a bit disconcerting when extra lines are added to your script. You can take another approach that may make more sense and might feel like you're more in control.



Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint