The following example shows how you can change the background color and alpha of a PopUpButton control’s pop up menu in Flex by setting the popUpStyleName, backgroundAlpha, and backgroundColor styles.

Full code after the jump.

View MXML

<?xml version="1.0"?>
<!-- http://blog.flexexamples.com/2008/01/17/setting-the-background-color-and-background-alpha-on-a-flex-popupbutton-controls-pop-up-menu/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="top"
        backgroundColor="white">

    <mx:Script>
        <![CDATA[
            import mx.controls.Menu;
            import mx.events.MenuEvent;

            [Bindable]
            private var menu:Menu;

            private function initMenu():void {
                menu = new Menu();
                menu.dataProvider = arr;
                menu.setStyle("themeColor", "black");
            }
        ]]>
    </mx:Script>

    <mx:Array id="arr">
        <mx:Object label="Button" />
        <mx:Object label="ButtonBar" />
        <mx:Object label="ColorPicker" />
        <mx:Object label="ComboBox" />
    </mx:Array>

    <mx:Style>
        .myPop {
            backgroundAlpha: 0.7;
            backgroundColor: black;
            borderStyle: none;
            color: white;
        }
    </mx:Style>

    <mx:ApplicationControlBar dock="true">
        <mx:PopUpButton id="popUpButton"
                label="Select a control..."
                popUp="{menu}"
                popUpStyleName="myPop"
                preinitialize="initMenu();" />
    </mx:ApplicationControlBar>

    <mx:VBox backgroundColor="haloSilver"
            width="100%"
            height="100%" />

</mx:Application>

View source is enabled in the following example.

 
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.

2 Responses to Setting the background color and background alpha on a Flex PopUpButton control’s pop up menu

  1. mohammed says:

    awesome ……………it helped……..saved my day……..thanks

  2. Luis says:

    Thanks, the common error is thinking about it as an percent value (70%), and here we can see that it is a decimal value (0.7).

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