Styling the Alert control’s nested buttons

by Peter deHaan on January 3, 2008

in Alert

The following example shows how you can customize the appearance of the buttons in an Alert control in Flex by setting the buttonStyleName style.

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-nested-buttons/ -->
<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 {
            buttonStyleName: myCustomButtonStyleName;
        }

        .myCustomButtonStyleName {
            color: red;
            cornerRadius: 12;
            fontFamily: myComicSansMS;
            fontSize: 10;
            fontWeight: normal;
            textDecoration: underline;
            themeColor: red;
        }
    </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);
            }
        ]]>
    </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.

{ 4 comments… read them below or add one }

1 peterd January 3, 2008 at 5:33 pm

Oops, I’ll post the SWF/source when I get home later tonight. I thought I uploaded it before work, but apparently not.

Peter

Reply

2 dormouse January 3, 2008 at 5:53 pm

Why define @font-face twice?

Thanks for your examples!

Reply

3 peterd January 3, 2008 at 6:16 pm

dormouse,

Good catch!
Looks like a copy/paste error. I just copied a previous entry, tweaked some styles and try and pass it off as a new, unique entry.

I’ll try and clean that up when I recreate the SWF files from home.

Peter

Reply

4 peterd January 3, 2008 at 10:37 pm

Posted and fixed.

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: