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.

 
Tagged with:
 
About The Author

Peter deHaan

Peter deHaan currently works for Adobe on the Flex SDK QA team. While not working on Flex, Flash, and ColdFusion applications, Peter enjoys making up bios and writing in 3rd person. Peter's rarely updated blog can be found at blogs.adobe.com/pdehaan/, actionscriptexamples.com, airexamples.com, and coldfusionexamples.com.

4 Responses to Adding a title icon to a Flex Alert control

  1. zlatko says:

    It it possible to load icon in runtime ?

  2. Simon says:

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

    Thanks

  3. Anonymous says:

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

  4. Rajeev says:

    Just love this site…..I am highly impressed with way practical content is put and the examples and everything…

Leave a Reply

Your email address will not be published.

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