22
Oct
07

Adding a title icon to a Flex Alert control

The following example shows how you can set both the titleIcon property and iconClass property for a Flex Alert control.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/10/22/adding-a-title-icon-to-a-flex-alert-control/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

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

            [Embed(source="assets/bulletCritical.png")]
            private var BulletCritical:Class;

            [Embed(source="assets/iconCritical.png")]
            private var IconCritical:Class;

            private var alert:Alert;

            private function init():void {
                var alertText:String = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse rutrum metus nonummy augue. In hac habitasse platea dictumst. Nulla arcu libero, nonummy non, suscipit a, mollis non, augue. Maecenas porttitor urna vel enim. Nam eget tortor. Mauris facilisis suscipit felis. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Proin nunc turpis, venenatis non, laoreet at, fringilla nec, purus. Sed sodales. Sed turpis. Vestibulum sagittis justo id metus. Sed placerat, nibh lobortis mattis adipiscing, sapien wisi interdum arcu, nec vehicula sem tortor id nibh.";
                var alertTitle:String = "The quick brown fox jumped over the lazy dog.";
                alert = Alert.show(alertText, alertTitle, 4, null, null, IconCritical);
                alert.titleIcon = BulletCritical;
            }
        ]]>
    </mx:Script>

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

</mx:Application>

View source is enabled in the following example.


3 Responses to “Adding a title icon to a Flex Alert control”


  1. 1 zlatko Oct 23rd, 2007 at 7:40 am

    It it possible to load icon in runtime ?

  2. 2 Simon Nov 27th, 2008 at 10:42 pm

    I will be interested to know how to load icon at runtime as well

    Thanks

  3. 3 Anonymous Jan 13th, 2009 at 4:55 am

    How to align the Icon in the IconCritical to the top than vertical center ?

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




Badge Farm

  • Powered by Redoable 1.2
  • Cornify
  • Feeds burnt by Feedburner
  • Feed