In a previous example, “Setting the border alpha on a Panel container in Flex”, we saw how you could change a panel’s border alpha by setting the borderAlpha style.

The following example shows how you can set the background alpha on a Flex Panel container by setting the backgroundAlpha style.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/03/12/setting-the-background-alpha-on-a-panel-container-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        creationComplete="init();">

    <mx:Style>
        Application {
            backgroundColor: red;
            backgroundGradientColors: red, black;
        }
    </mx:Style>

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

            private function init():void {
                slider.value = panel.getStyle("backgroundAlpha");
            }

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

    <mx:ApplicationControlBar dock="true">
        <mx:Label text="backgroundAlpha:" />
        <mx:HSlider id="slider"
                minimum="0.0"
                maximum="1.0"
                liveDragging="true"
                snapInterval="0.01"
                tickInterval="0.1"
                change="slider_change(event);" />
    </mx:ApplicationControlBar>

    <mx:Panel id="panel" title="Panel" width="100%" height="100%">
        <mx:ControlBar>
            <mx:Label text="ControlBar" />
        </mx:ControlBar>
    </mx:Panel>

</mx:Application>

View source is enabled in the following example.

You can also set the backgroundAlpha style in MXML, using the following snippet:

<mx:Panel title="Panel" backgroundAlpha="0.75">
...
</mx:Panel>

Or you can set the backgroundAlpha style in an external .CSS file or a <mx:Style /> block, as seen in the following snippet:

<mx:Style>
    Panel {
        backgroundAlpha: 0.75; /* 75% */
    }
</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 alpha on a Panel container in Flex

  1. aryan says:

    <3 ur examples.
    great demonstration

  2. Derek says:

    How do you get it so that the part of the panel that holds the titleBar and controlBar is transparent? I want that part of the panel to just be white, straight up, but the area that holds the children will have its own styles

  3. ajay says:

    try Multiple columns dynamically filtered..
    http://code.google.com/p/flexdynamicfilter/

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