Alert Dialogs (mx.controls.Alert)
The Alert control is used to easily create a pop-up dialog.
An Alert dialog box that can contain a message, a title, buttons
(any combination of OK, Cancel, Yes, and No) and an icon.
The ActionScript Alert class is in the mx.controls package.
The easiest way to show an Alert message is via the static show() function.
Display an Alert dialog via a static method call:
// show an alert dialog Alert.show( "This is a message!", "Dialog Title" );

The Alert control is modal by default, which means it will retain focus until the user closes it. The Alert control closes when a button is selected or the Escape key is pressed.
Advanced Alerts
The Alert class can be used for more than displaying a simple mesage. Using the Alert class you can also ask
The static show() function takes in several arguments, many of them optional, detailed below.
Arguments to the show() function:
| Argument | Type | Default | Description |
|---|---|---|---|
| text | String | "" | The text to display in the dialog |
| title | String | "" | The dialog title |
| flags | uint | Alert.OK | Bit-flags that affect Alert options, such as which buttons are shown |
| parent | Sprite | null | The parent of the dialog (usually this will suffice) |
| closeHandler | Function | null | The function to be called when the Alert is closed |
| iconClass | Class | null | An image or icon to show with the Alert |
| defaultButtonFlag | uint | Alert.OK | A bit-flag to specify the default button |
The flags argument to the show() function accepts bit-flags.
The acceptable flags are constants of the Alert class:
- OK - enables an OK button on the Alert control
- YES - enables a Yes button on the Alert control
- NO - enables a No button on the Alert control
- CANCEL - enables a Cancel button on the Alert control
- NONMODAL - makes the Alert non-modal
The flags argument is passed as "bit-or" seperated values.
For example, passing Alert.YES | Alert.NO | Alert.CANCEL means
show "Yes", "No", and "Cancel" buttons on the dialog.
Bit-flags allow you to pass several on/off options as a single argument to a function.
Examples using Alert
The Alert dialog can be used in a variety of situations.
Show a Yes or No Dialog
The Alert class can be used to easily prompt a user to answer a yes/no question.
We'll use the Alert.YES and Alert.NO flags to show "Yes"/"No" buttons.
Show a Yes/No prompt with Alert:
// show an alert with a question and yes and no choices Alert.show( "Would you like to choose yes or no?", "Question", Alert.YES | Alert.NO, this, closeHandler, null, Alert.YES );

Note that the "Yes" button is the default button because we passed the Alert.YES
value as the (last) defaultButtonFlag argument.
Show a Non-Modal Alert Dialog
By default an Alert dialog is modal, meaning it retains focus, blocking the background,
until the user closes it.
However, you can show a non-modal dialog by using the Alert.NONMODAL flag.
Show a non-modal Alert dialog:
// show a non-modal alert Alert.show( "This is dialog is non-modal.", "Non-Modal", Alert.NONMODAL );
Advanced Dialogs beyond Alerts
Learn more about creating advanced dialogs in Flex...
Related Links:
For more information on the Alert API, checkout the Flex reference docs for the Alert class.

