Styling Alert controls in Flex using the StyleManager class and setStyle() method (Flex 4 Edition)

In a previous example, “Styling Alert controls in Flex using the StyleManager class and setStyle() methods”, we saw how to style a Flex Alert control using the static StyleManager.getStyleDeclaration() method, and the setStyle() method.

The following example shows how you can do the same thing using the beta Flex 4 SDK by passing a fully qualified class name to the static getStyleDeclaration() method.

The following example(s) require Flash Player 10 and the Adobe Flex 4 SDK. To download the Adobe Flash Builder 4 trial, see www.adobe.com/products/flex/. To download the latest nightly build of the Flex 4 SDK, see opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4.

For more information on getting started with Flex 4 and Flash Builder 4, see the official Adobe Flex Team blog.

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2009/04/06/styling-alert-controls-in-flex-using-the-stylemanager-class-and-setstyle-method-spark-edition/ -->
<s:Application name="MX_Alert_chromeColor_test"
        xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/mx"
        initialize="init();">
 
    <fx:Script>
        <![CDATA[
            import mx.controls.Alert;
 
            private var alert:Alert;
            private var alertCSS:CSSStyleDeclaration;
 
            private function init():void {
                alertCSS = styleManager.getStyleDeclaration("mx.controls.Alert");
            }
 
            private function showAlert(color:Object):void {
                alertCSS.setStyle("modalTransparencyColor", color);
                alertCSS.setStyle("chromeColor", color);
                alert = Alert.show("The quick brown fox jumps over the lazy dog.", "Alert title");
            }
        ]]>
    </fx:Script>
 
    <s:controlBarContent>
        <s:Button label="Red"
                  chromeColor="red"
                  click="showAlert('red');" />
        <s:Button label="Orange"
                  chromeColor="haloOrange"
                  click="showAlert('haloOrange');" />
        <s:Button label="Yellow"
                  chromeColor="yellow"
                  click="showAlert('yellow');" />
        <s:Button label="Green"
                  chromeColor="haloGreen"
                  click="showAlert('haloGreen');" />
        <s:Button label="Blue"
                  chromeColor="haloBlue"
                  click="showAlert('haloBlue');" />
    </s:controlBarContent>
 
</s:Application>

[GoogleAdsWide]

View source is enabled in the following example.

This entry is based on a beta version of the Flex 4 SDK and therefore is very likely to change as development of the Flex SDK continues. The API can (and will) change causing examples to possibly not compile in newer versions of the Flex 4 SDK.

4 thoughts on “Styling Alert controls in Flex using the StyleManager class and setStyle() method (Flex 4 Edition)

  1. Thank you Peter, but do you know why with Gumbo ( I use FB 4 beta ) not all properties of Alert work. For example

    alertCSS.setStyle(“cornerRadius”, 5);

    doesn’t work.

  2. Without styleManager, and not persistant :
    var a:Alert = Alert.show(‘blabla’);
    a.setStyle(‘chromeColor’, ‘red’);

Comments are closed.