The following code shows a very basic method for displaying an Alert dialog in a Flex application. As this is a very simple example, it doesn’t show how to properly determine which button the user clicked to dismiss the dialog box, nor does it show other techniques such as modal versus non-modal dialog boxes. I’ll try and cover those in later entries.
Full code after the jump.
The following example displays a simple Alert when the user presses the Button control. The alert has two buttons, “Yes” and “No” which the user can use to dismiss the dialog:
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/wp-content/uploads/Alert_closeHandler_test/bin/srcview/index.html -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
private var alert:Alert;
private function showAlert():void {
var text:String = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.nntHello World";
var title:String = "This is the title of the Alert window";
alert = Alert.show(text, title, Alert.YES | Alert.NO);
}
]]>
</mx:Script>
<mx:Button label="Alert.show()" click="showAlert();" />
</mx:Application>
View source is enabled in the following example.



Hi,
I’m calling Alert.show with a title and a string, but I never see the title - it’s as if it gets cut off! Any ideas why my title never shows up?
Alert.show("My text", "Title");Thanks,
AB