Just as a set of events is associated with movie clip symbols, a set of events is also associated with button symbols. You can use button event handler methods with button instances. (You can also use button events with movie clips; see Using button events with movie clips to trigger scripts.)
You can either call an event handler method from the instance of the button whose event you want to handle, or create a new ActionScript class and define the methods in the prototype object of the class. For information about defining a method in the prototype object, see Defining event handler methods in a class definition.
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:
object
parameter, enter the target path for the button whose event you want to handle.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!"); };