18
Jul
07

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.

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:

View MXML

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


1 Response to “Using the Alert control”


  1. 1 Asli Binal Dec 5th, 2007 at 12:11 pm

    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

Leave a Reply

This blog is terrible at eating HTML tags. If you plan on posting code/XML, please escape your "<" characters as "&lt;" and your ">" characters as "&gt;".




July 2007
M T W T F S S
    Aug »
 1
2345678
9101112131415
16171819202122
23242526272829
3031  

Badge Farm

  • Firefox 2
  • Powered by Redoable 1.2
  • Feeds burnt by Feedburner
  • Feed