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

Hour 14. Using ActionScript to Create No... > Task: Place Actions on a Movie Clip ...

Task: Place Actions on a Movie Clip Instance

Create a Movie Clip that contains several frames and some kind of animation inside the clip (so we can see whether it's playing).

Place this Movie Clip onstage and test the movie (to verify it's animating). Your main timeline should have only one frame.

Back in Flash, select the instance of the Movie Clip onstage and open the Actions panel. Notice that almost all the Actions in the Toolbox List are available (that is, they're not grayed out).

From the plus button select Actions, Movie Control, stop. Notice that Actions attached to Movie Clip instances have to be wrapped inside an onClipEvent. The default clip event is load, so you should see something like Figure 14.9.

Figure 14.9. A stop Action attached to a Movie Clip is automatically surrounded by an onClipEvent.

Test the movie now and, when the Movie Clip loads (that is, when it first appears onstage), it stops. Another way to create the same effect is to put a stop Action on the first keyframe inside the master Movie Clip. There's nothing wrong with that technique, but a stop inside the master Movie Clip means every instance will exhibit this behavior. Placing the Action on one instance—as we did—affects just that one.

We will add two more Actions that respond to the mouse down and mouse up events. When the user clicks (mouse down), the Movie Clip should start to play. When he stops clicking (that is, mouse up), the Movie Clip should stop. If the line currently selected in your script is within the curly braces, you won't be adding another clip event, because you can't put an event inside an event. Remember: Every time you add an Action, Flash will try to put the Action right below the line currently selected in your script. However, you can drag the onClipEvent script (from the Toolbox section under Actions, Movie Clip Control)below the ending curly brace. Alternatively, you can select the last line and then select the plus button, Actions, Movie Control, onClipEvent.

Before we add more clip events, drag a stop Action to appear right underneath the first line in the clip event you added in the last step. To add more clip events, drag a play Action (from the Toolbox section) below the last line in your script. It will automatically be wrapped inside an onClipEvent load script.

It doesn't make too much sense the way it is now because you have three versions of onClipEvent (load). Leave the first you created alone. Click the first line of the second event (the one with stop inside). With this line selected, you can change the parameters of the clip event to respond to mouse up instead of load. The last event should start with a clip event of mouse down. When you're done making edits to this script, it should look like that shown in Figure 14.10. The order of the three events is unimportant—just the particular events and contained scripts.

Figure 14.10. The complete set of Actions for this Movie Clip.

Test the movie. It's actually pretty sophisticated, despite the simplicity of the script. Go back and re-read the script (in the Script Area of the Actions panel) attached to our Movie Clip instance.

There are a few important things to note about this exercise. First, the clip events mouse down and mouse up respond to any mouse click—not just clicks on the clip itself. If you want something that responds to clicks right on a graphic, using a regular button is easiest.



Not a subscriber?

Start A Free Trial

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