Search Flex Samples

Using the Alert control

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.

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"?>

<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>

0 comments:

Related Flex Samples

Learn Flex: Flex Samples | Flex Video Tutorials Flex Examples