Working with Movie Clips and Buttons > Handling events with ActionScript > Using movie clip event handler methods to trigger scripts |
![]() ![]() ![]() |
Using movie clip event handler methods to trigger scripts
You can use the methods in the Events category of the MovieClip object to handle movie clip events. You must define a function and assign it to the event handler method. Without a function assigned to it, the event handler method has no effect on the movie.
You can either call an event handler method from the instance of the movie clip whose event you want to handle, or create a new ActionScript class and define the methods in the prototype object of the class. (For more information, see Defining event handler methods in the prototype object.)
To use a movie clip event handler method to trigger a script:
1 |
On the Stage, select the movie clip 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 |
![]() |
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 |
|
mc.onPress = function() { this._alpha = 50; }; |
|
Note: The keyword |
![]() ![]() ![]() |