The Alert control is a pop-up dialog box that contains a title, buttons (such as OK, Cancel, etc.) and an icon. It is normally used by application programmers to convey the occurance of an unexpected event in the system.
You use the static show() method to display an Alert control, or for convenience you can use Application.alert().
getViewMetrics(
)
:
Object Gets the thickness of the edges of the Alert dialog, including the border, title bar, and scroll bars, if visible.
static
show(
text:
String, title:
String, flags:
Number, parent:
MovieClip, listener, icon:
String, defButton:
Number)
:
mx.controls.Alert Static method that shows the Alert control with the title, message, and requested buttons.
Static method that shows the Alert control with the title, message, and requested buttons.
Note: The Alert.show() and Application.alert() methods appear similar but have different parameter ordering.
Also note that icon is a URL to an image file that appears in the control. Image types include JPEG, GIF, PNG, BMP, and SWF. You use the following format with this property: icon="@Embed('relOrAbsoluteURL')" The referenced image is packaged in the generated SWF file at compile time when Flex creates the SWF file for your application.
Parameters text:
String - Text string that appears in the Alert control. title:
String - Text string in the title bar. flags:
Number - Which buttons to place in the Alert control. Valid values are YES, NO, CANCEL, OK. Use the bitwise OR operator to enable more than one button. For example (Alert.YES | Alert.NO). parent:
MovieClip - Object upon which the Alert control centers itself. listener - object that is triggered when any button on the Alert control is pressed. The object should have a click() method in order to get correctly called. icon:
String - Icon that is placed to the left of the text in the Alert control. defButton:
Number - the default button; One of YES, NO, CANCEL, OK.
Property Detail
buttonHeight
static
buttonHeight:
Number
Height of Alert buttons, in pixels. The default value is 22 pixels.
buttonStyleDeclaration
static
buttonStyleDeclaration:
String
Style declaration name for the button text.
buttonWidth
static
buttonWidth:
Number
Width of Alert buttons, in pixels. The default value is 50 pixels.
CANCEL
static
CANCEL:
Number
Flag used for enabling a 'Cancel' button on the Alert
cancelLabel
static
cancelLabel:
String
Label for the Cancel button. The default value is "Cancel".
messageStyleDeclaration
static
messageStyleDeclaration:
String
Style declaration name for the message text.
NO
static
NO:
Number
Flag used for enabling a 'No' button on the Alert
noLabel
static
noLabel:
String
Label for the No button. The default value is "No".
OK
static
OK:
Number
Flag used for enabling a 'OK' button on the Alert
okLabel
static
okLabel:
String
Label for the OK button. The default value is "OK".
titleStyleDeclaration
static
titleStyleDeclaration:
String
Style declaration name for the text in the title bar.
version
static
version:
String
Version string for this class.
YES
static
YES:
Number
Flag used for enabling a 'Yes' button on the Alert
yesLabel
static
yesLabel:
String
Label for the Yes button. The default value is "Yes".
Examples
SimpleAlert.mxml
<?xml version="1.0"?>
<!-- Simple example to demonstrate the Alert control -->
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" backgroundColor="#FFFFFF">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
/** Event handler function imports the Alert control, which uses a static method to show
a pop-up window with the title, message, and requested buttons.
**/
function Alerted()
{
Alert.show("You have been alerted !!", "Alert Box",Alert.OK);
}
]]>
</mx:Script>
<mx:Panel title="Alert Panel" marginTop="10">
<mx:Button label="Alert me" click="Alerted();"/>
</mx:Panel>
</mx:Application>
Comments
Eric Raymond
said on
Apr 8, 2005
at
2:51 PM :
The click handler is called with an event object as a parameter. The detail property on the event indicates which button was pressed.
Comments
Eric Raymond said on Apr 8, 2005 at 2:51 PM :