ActionScript 2.0 Components Language Reference |
|
|
|
| Alert component > Alert.click | |||
Flash Player 6 (6.0.79.0).
Flash MX Professional 2004.
var clickHandler:Function = function(eventObject:Object) {// Insert code here.}Alert.show(message[,title[,flags[,parent[,clickHandler[,icon[,defaultButton]]]]]])
Event; broadcast to the registered listener when the OK, Yes, No, or Cancel button is clicked.
Components use a dispatcher/listener event model. The Alert component dispatches a click event when one of its buttons is clicked and the event is handled by a function, also called a handler, on a listener object (listenerObject) that you create. You call the Alert.show() method and pass it the name of the handler as a parameter. When a button in the Alert window is clicked, the listener is called.
When the event occurs, it automatically passes an event object (eventObject) to the handler. Each event object has properties that contain information about the event. You can use these properties to write code that handles the event. The Alert.click event's event object has an additional detail property whose value is Alert.OK, Alert.CANCEL, Alert.YES, or Alert.NO, depending on which button was clicked. For more information, see EventDispatcher class.
With an Alert component already in the library, add this ActionScript to the first frame of the main timeline to create an event handler called myClickHandler. The event handler is passed to the Alert.show() method as the fifth parameter. The event object is captured by myClickHandler in the evt parameter. The detail property of the event object is then used in a trace statement to send the name of the button that was clicked (Alert.OK or Alert.CANCEL) to the Output panel.
import mx.controls.Alert;
// Define button actions.
var myClickHandler:Function = function (evt_obj:Object) {
switch (evt_obj.detail) {
case Alert.OK :
trace("You clicked: " + Alert.okLabel);
break;
case Alert.CANCEL :
trace("You clicked: " + Alert.cancelLabel);
break;
}
};
// Display dialog box.
Alert.show("This is a test of errors", "Error", Alert.OK | Alert.CANCEL, this, myClickHandler);
|
|
|
|