Adding a title icon to a Flex Alert control

by Peter deHaan on October 22, 2007

in Alert

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 comments… read them below or add one }

1 zlatko October 23, 2007 at 7:40 am

It it possible to load icon in runtime ?

Reply

2 Simon November 27, 2008 at 10:42 pm

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

Thanks

Reply

3 Anonymous January 13, 2009 at 4:55 am

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

Reply

Leave a Comment

Sorry, this blog is terrible at eating HTML comments.
If you're pasting any HTML/XML/MXML code, you need to convert your < characters to &lt; and your > characters to &gt; .

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Anti-Spam Protection by WP-SpamFree

Previous post:

Next post: