The following example shows how you can change the background color and background alpha on a LinkBar control in Flex by setting the backgroundColor and backgroundAlpha styles using either MXML, ActionScript, or CSS.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/01/21/setting-the-background-color-and-background-alpha-on-a-flex-linkbar-control/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Array id="arr">
        <mx:Object label="One" />
        <mx:Object label="Two" />
        <mx:Object label="Three" />
        <mx:Object label="Four" />
    </mx:Array>

    <mx:ApplicationControlBar dock="true">
        <mx:Form styleName="plain">
            <mx:FormItem label="backgroundAlpha:">
                <mx:HSlider id="slider"
                        minimum="0.0"
                        maximum="1.0"
                        value="1.0"
                        liveDragging="true" />
            </mx:FormItem>
        </mx:Form>
    </mx:ApplicationControlBar>

    <mx:LinkBar id="linkBar"
            dataProvider="{arr}"
            backgroundAlpha="{slider.value}"
            backgroundColor="haloBlue" />

</mx:Application>

View source is enabled in the following example.

You can also set the backgroundAlpha style using ActionScript, as seen in the following snippet:

<mx:Script>
    <![CDATA[
        import mx.events.SliderEvent;

        private function slider_change(evt:SliderEvent):void {
            linkBar.setStyle("backgroundAlpha", evt.value);
        }
    ]]>
</mx:Script>

Or, you can also set the backgroundAlpha and backgroundColor styles in an external .CSS file or <mx:Style /> block, as shown in the following snippet:

<mx:Style>
    LinkBar {
        backgroundAlpha: 0.4;
        backgroundColor: red;
    }
</mx:Style>
 
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.

3 Responses to Setting the background color and background alpha on a Flex LinkBar control

  1. jon says:

    great examples

    thanks a lots

  2. andrew says:

    When I was converting a Flex 3 version of LinkBar to Flex 4 (Spark theme), I found the backgroundAlpha attribute did not work. The one you need to use in Flex 4 is contentBackgroundAlpha. I not sure why.

  3. Jeppe says:

    @Andrew: Thank you for the contentBackgroundAlpha info. I was just about to give up, when I found your post.

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