Button Events
Top  Previous  Next


Button Events occur when the mouse interacts with an Object in a Scene or a defined key is pressed. Adding a Button Event to an Object makes it behave like a button and allows it to respond to the mouse and keyboard.

More than one Button Event can trigger the same Action, as shown in the example below.

The Actions in a Button Event Handler apply to the Scene or Sprite containing the Object. For example, if a Sprite has a Button Event Handler that contains a stop() Action, then that Action stops the Scene containing the Sprite, it does not stop the Sprite itself. If you want the Actions to apply to a Sprite, then use a Sprite Event instead.

You can insert a Button Event either by going to the Script Panel, selecting an Object, and pressing Add Event.

When you select a Button Event for an Object, the Button Event Properties are shown adjacent to the 'Event/Action' tree in the Script Panel.

buttonevents-options  

This contains a list of check boxes showing the Button Events. You can select a combination of Button Events, such as Roll Over and Roll Out, so that the same list of Actions can be performed for different Events. The Events and their triggers are described below:

·on (press): press the left mouse button while the cursor is over the button  
·on (release): release the left mouse button while the cursor is over the button  
·on (rollOver): move the mouse cursor from outside the button to over it with no mouse button pressed  
·on (rollOut): move the mouse cursor from over the button to outside it with no mouse button pressed  
·on (dragOver): move the mouse cursor from outside the button to over it with the left mouse button pressed  
·on (dragOut): move the mouse cursor from over the button to outside it with the left mouse button pressed  
·on (releaseOut): release the left mouse button after moving the cursor outside the button  
·on (keyPress): press the define Key. The required key can be entered in the Key field or selected from the common keys drop-down Menu.  

Note: Due to limitations of the Flash Player, the Play Sound and Stop Sound Action cannot be triggered by Drag Over, Drag Out or Release Outside Events. A simple way around this limitation is to place your sounds in a Sprite called "sound", then use Actions such as sound.gotoAndPlay(2) where Frame 2 of the Sprite will cause the sound to play

In the example below, both Press and Roll Over Actions will send the Movie to Frame one.

buttonevents-example  
 
Note: Button Events are assumed to work on the _root or main Movie layer. Consequently Actions such as _X += 5; which may be expected to move the button, will actually move the entire Movie to the right by 5 pixels