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 http://www.adobe.com/products/flex/. To download the latest nightly build of the Flex 4 SDK, see http://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>

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.

 
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 Styling Alert controls in Flex using the StyleManager class and setStyle() method (Flex 4 Edition)

  1. gregloby says:

    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. Peter deHaan says:

    gregloby,

    In Flex 4, not all the styles are supported by the default spark skins. The easiest solution is to create a custom skin.

    In fact, I’ll create a new post since the code is a bit long to put here… Stay tuned.

    Peter

    For an example, see Setting the corner radius on the Halo Alert control in Flex 4.

  3. greg says:

    Thank you Peter,
    you’re great :)

  4. Breinz says:

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

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