home support FAQ resources services partners contact us contact us
 Flash MX Previous  Next  
 Tutorial

When you use an event handler method with a button, the keyword this refers to the button instance that calls the method. For example, the following code sends _level0.myButton to the Output window:

myButton.onPress = function() {
trace(this);
}

To use a button event handler method to trigger a script:
1 On the Stage, select the button instance whose event you want to handle.
2 Enter an instance name in the Property inspector.
3 Select a frame, button, or movie clip to which to attach the method.
4 Choose Window > Actions to open the Actions panel if it isn’t already open.
5 In the Actions toolbox (at the left of the panel), click the Objects category, then click the Movie category, the MovieClip category, and the Events category, and double-click one of the MovieClip event handler methods.

6 Enter values for the following parameters:

• For the object parameter, enter the target path for the button whose event you want to handle.
• Pass any parameters needed by the function you will define. (In normal mode, enter these parameters in the Parameters text box.)

7 Add actions inside the function to define the function.

The following code defines a function for the onPress method of the instance myButton that triggers a trace action:

myButton.onPress = function() {
trace("onPress called!");
};

Using button events with movie clips to trigger scripts

You can use button events with button instances, but you can also use them with movie clip instances to create button movie clips. Button movie clips combine the power of movie clips with the control of button events. You can turn a movie clip into a button movie clip by assigning an on handler to the movie clip instance, or by defining button event handler methods for an instance. You can also create a new class and define event handler methods in the prototype object of that class. (For information about defining methods in the prototype object,

All button events are triggered by user interaction: press, release, releaseOutside, rollOver, rollOut, dragOver, dragOut, and keyPress. In the Actions toolbox, the MovieClip object has an Events category containing methods that correspond to each button event, such as onPress, onRelease, onReleaseOutside, onRollOver, onRollOut, onDragOver, onDragOut, and onKeyPress.
Previous  Next  
Link Partners: Asia florist, Flowers to India, Hong kong flowers, Site submit, Cheap web hosting, China florist, Japan florist