21
Jan
08

Setting the background color and background alpha on a Flex LinkBar control

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>

1 Response to “Setting the background color and background alpha on a Flex LinkBar control”


  1. 1 jon Jan 23rd, 2008 at 2:21 am

    great examples

    thanks a lots

Leave a Reply

This blog is terrible at eating HTML tags. If you plan on posting code/XML, please escape your "<" characters as "&lt;" and your ">" characters as "&gt;".