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

Chapter 15. Using Basic ActionScripts > Attaching a Clip Event to a Movie Clip

Attaching a Clip Event to a Movie Clip

You can only attach an onClipEvent() to a movie clip instance that has been placed on the Stage. You can't attach an onClipEvent() to a movie clip instance that is created at runtime; for example, using the attachMovie() method. Using different event handlers within the same Flash document do not conflict with each other. For example, you could have a button with an on(press) handler that tells the .swf file to play, and the same button can have an onPress method, for which you define a function that tells an object on the Stage to rotate. When the button is clicked, the SWF file plays, and the object will rotate. Being able to consolidate different event handlers with a single instance, gives you greater control, as well as less Stage clutter.

Attach an onClipEvent to a Movie Clip

Place a movie clip on the Stage, and then select the movie clip.

Give the movie clip a unique instance name in the Properties panel.

Move down the Timeline and add a keyframe at frame 80.

Click the Insert menu, point to Timeline, and then click Keyframe.

Add a second movie clip to the Stage, and then select the second movie clip.

Enter the script as shown in the illustration.

Click the Control menu, and then click Test Movie.

When the playhead hits frame 80 it loads the second movie clip. The loading of the movie will trigger the onClipEvent handler, and stop the playing of the movie clip with the unique instance name of movie2.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


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