Flash CS4 Professional ActionScript 2.0

Alert.show()

Availability

Flash Player 6 (6.0.79.0).

Edition

Flash MX Professional 2004.

Usage

Alert.show(message[, title[, flags[, parent[, clickHandler[, icon[, defaultButton]]]]]])

Parameters

message The message to display.

title The text in the Alert title bar. This parameter is optional; if you omit it, the title bar is blank.

flags An optional parameter that indicates the buttons to display in the Alert window. The default value is Alert.OK, which displays an OK button. When you use more than one value, separate the values with a | character. Use one or more of the following values: Alert.OK, Alert.CANCEL, Alert.YES, Alert.NO.

You can also use Alert.NONMODAL to indicate that the Alert window is nonmodal. A nonmodal window allows a user to interact with other windows in the application.

parent The parent window for the Alert component. The Alert window centers itself in the parent window. Use the value null or undefined to specify the _root timeline. The parent window must be a subclass of the UIComponent class, either as another Flash component that is a subclass of UIComponent, or as a custom window that is a subclass of the UIComponent (for more information see About inheritance in Learning ActionScript 2.0 in Adobe Flash). This parameter is optional.

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 in Using ActionScript 2.0 Components.

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. (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):

import mx.controls.Alert;

// Define button actions.
var myClickHandler:Function = function (evt_obj:Object) {
 if (evt_obj.detail == Alert.OK) {
trace(Alert.okLabel);
 } else if (evt_obj.detail == Alert.CANCEL) {
trace(Alert.cancelLabel);
 }
};

// Display dialog box.
var dialog_obj:Object = Alert.show("Test Alert", "Test", Alert.OK | Alert.CANCEL, null, myClickHandler, "testIcon", Alert.OK);