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

Chapter 15. Using Basic ActionScripts > Attaching a Mouse Event to a Button

Attaching a Mouse Event to a Button

Attaching a mouse event to a button is probably the easiest of all the events handlers. For example, you have a movie clip of a dog that contains a barking audio file. When the movie clip plays, the dog barks. However, the trick is you want to have the dog bark when the visitor rolls their mouse over the dogs face. To do this, you will need to create an invisible button, and then attach the mouse event to the invisible button.

Attach an Event to a Button

Click the Insert menu, and then click New Symbol.

Select the Button option, and then name the Symbol.

Click OK.

Create a blank keyframe in the Hit state of the button, and then create a shape.

Leave the Up, Over, and Down states blank.

Exit the Symbol editing mode, and then return to the Stage.

Drag a movie clip onto the Stage.

Create a new layer, and then name the layer.

Drag the invisible button onto the Stage, and then place it over the area of the image you want to use as a button.

Enter the script as shown in the illustration.

When the visitor rolls into or out of the invisible button, the rollOver or rollOut event handlers will trigger the playing or stopping of the dog movie clip.

Click the Control menu, and then click Test Movie.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


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