03
Jan
08

Styling the Alert control’s status message

The following example shows how you can customize the appearance of the status message in an Alert control in Flex by setting the statusStyleName style and status property.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/01/03/styling-the-alert-controls-status-message/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        creationComplete="init();">

    <mx:Style>
        @font-face {
            src: local("Comic Sans MS");
            fontFamily: myComicSansMS;
            fontWeight: normal;
        }

        Alert {
            statusStyleName: myCustomStatusStyleName;
        }

        .myCustomStatusStyleName {
            color: red;
            fontFamily: myComicSansMS;
            fontSize: 10;
            fontWeight: normal;
        }
    </mx:Style>

    <mx:Script>
        <![CDATA[
            import mx.controls.Alert;

            private var alert:Alert;

            private function init():void {
                var myMessage:String = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.\nDonec tincidunt sollicitudin sem.";
                var myTitle:String = "The quick brown fox jumped over the lazy dog";
                alert = Alert.show(myMessage, myTitle);
                alert.status = "status message";
            }
        ]]>
    </mx:Script>

    <mx:ApplicationControlBar dock="true">
        <mx:Button label="Launch alert" click="init();" />
    </mx:ApplicationControlBar>

</mx:Application>

View source is enabled in the following example.


2 Responses to “Styling the Alert control's status message”


  1. 1 udayms Jan 4th, 2008 at 5:29 am

    One doubt. What is “Status” used for? I mean, whats its purpose?

  2. 2 peterd Jan 4th, 2008 at 10:07 am

    udayms,
    The status just lets you add one more piece of information to the title bar. It is completely optional.
    It probably doesn’t make a lot of sense for most Alert control’s, but would be more useful on Panel and other containers.

    Peter

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;".