User Guide
Alert component (Flash Professional only) 129
clickHandler A handler for the click events broadcast when the buttons are clicked. In
addition to the standard click event object properties, there is an additional
detail property,
which contains the flag value of the button that was clicked (
Alert.OK, Alert.CANCEL,
Alert.YES, Alert.NO). This handler can be a function or an object. For more information, see
“Using listeners to handle events” on page 56.
icon A string that is the linkage identifier of a symbol in the library; this symbol is used as an
icon displayed to the left of the alert text. This parameter is optional.
defaultButton Indicates which button has initial focus and is clicked when a user presses
Enter (Windows) or Return (Macintosh). If a user tabs to another button, that button is triggered
when the Enter key is pressed.
This parameter can be one of the following values:
Alert.OK, Alert.CANCEL, Alert.YES,
Alert.NO.
Returns
The Alert instance that is created.
Description
Method (class); a class (static) method that displays an Alert window with a message, an optional
title, optional buttons, and an optional icon. The title of the alert appears at the top of the
window and is left-aligned. The icon appears to the left of the message text. The buttons are
centered below the message text and the icon.
Example
The following code is a simple example of a modal Alert window with an OK button:
mx.controls.Alert.show("Hello, world!");
The following code defines a click handler that sends a message to the Output panel about which
button was clicked:
import mx.controls.Alert;
myClickHandler = function(evt){
trace ("button " + evt.detail + " was clicked");
}
Alert.show("This is a test of errors", "Error", Alert.OK | Alert.CANCEL, this,
myClickHandler);
The event object’s detail property returns a number to represent each button. The OK button is
4, the Cancel button is 8, the Yes button is 1, and the No button is 2.
Note: You must have an Alert component in the library for this code to display an alert. To add the
component to the library, drag it to the Stage and then delete it.