Styling buttons in an Alert control

Here’s a basic example of applying a custom style to an Alert control’s buttons and giving them a nice, rounded effect.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/08/09/styling-buttons-in-an-alert-control/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white">

    <mx:Style>
        .roundedAlertButtons {
            cornerRadius: 10;
            font-weight: bold;
            color: black;
        }
    </mx:Style>

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

            private var alert:Alert;

            private function showAlert():void {
                alert = Alert.show("The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog.", "I'm an Alert control.", Alert.YES | Alert.NO);
                alert.setStyle("buttonStyleName", "roundedAlertButtons");
            }
        ]]>
    </mx:Script>

    <mx:Button label="Show alert" click="showAlert();" />

</mx:Application>

View source is enabled in the following example.

0 thoughts on “Styling buttons in an Alert control