F > FPushButton.setClickHandler

 

FPushButton.setClickHandler

Availability

Flash Player 6.

Usage

myPushButton.setClickHandler(functionName, [location])

Parameters

functionName A string specifying the name of the handler function to execute when the user releases the push button. If the location parameter is not specified, this function must be in the same Timeline as the component instance.

location A path reference to a data object, movie clip, or Timeline that contains the specified function. This parameter is optional and defaults to the parent Timeline of the component.

Returns

Nothing.

Description

Method; specifies a handler function to call when the user releases the push button. You can specify the same handler function for more than one component; the function always accepts the instance of the component that has changed as a parameter. Calling this method overrides the Click Handler parameter value specified in authoring.

For more information, see Writing change handler functions for components in the "Using Components" chapter of Using Flash.

Example

The following code specifies onClick as the function called when the value of button1 changes. Because the location parameter is not specified, onClick must be in the same Timeline as the component instance. The component parameter in onClick is automatically filled in with the instance of a component (the component that has changed as the result of user input and that specifies onClick as its change handler). The actions defined in onClick specify that when the user releases a button, the label of the button is written to the Output window.

button1.setClickHandler("onClick");
function onClick(component){ 
trace(component._name); 
} 

If in the preceding example onClick is a function located in the great-grandparent Timeline of the component's Timeline, the first line of code would be as follows:

button1.setChangeHandler("onClick", _parent._parent._parent);

The following code creates the function onClick in an instance of myObject (which is of class Object), and then specifies onClick as the function for button1.

myObject = new Object();
myObject.onClick = function(component){
trace(component._name); 
}
button1.setChangeHandler("onClick", myObject);