The following example shows how you can display a drop shadow behind a Flex VBox container by setting the borderStyle and dropShadowEnabled styles.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/09/24/displaying-a-drop-shadow-behind-a-vbox-container-in-flex/ -->
<mx:Application name="VBox_dropShadowEnabled_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:VBox id="vBox"
            dropShadowEnabled="true"
            borderStyle="solid"
            borderThickness="0"
            backgroundColor="red"
            width="100%"
            height="100%">
        <mx:Label text="{Capabilities.version}"
                fontSize="64" />
    </mx:VBox>

</mx:Application>

View source is enabled in the following example.

You can also set the borderStyle and dropShadowEnabled styles in an external .CSS file or <mx:Style /> block, as seen in the following example:

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/09/24/displaying-a-drop-shadow-behind-a-vbox-container-in-flex/ -->
<mx:Application name="VBox_dropShadowEnabled_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Style>
        VBox {
            dropShadowEnabled: true;
            borderStyle: solid;
            borderThickness: 0;
            backgroundColor: red;
        }
    </mx:Style>

    <mx:VBox id="vBox"
            width="100%"
            height="100%">
        <mx:Label text="{Capabilities.version}"
                fontSize="64" />
    </mx:VBox>

</mx:Application>

Or, you can set the borderStyle and dropShadowEnabled styles using ActionScript, as seen in the following example:

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/09/24/displaying-a-drop-shadow-behind-a-vbox-container-in-flex/ -->
<mx:Application name="VBox_dropShadowEnabled_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Script>
        <![CDATA[
            private function init():void {
                vBox.setStyle("dropShadowEnabled", true);
                vBox.setStyle("borderStyle", "solid");
                vBox.setStyle("borderThickness", 0);
                vBox.setStyle("backgroundColor", "red");
            }
        ]]>
    </mx:Script>

    <mx:VBox id="vBox"
            width="100%"
            height="100%"
            initialize="init();">
        <mx:Label text="{Capabilities.version}"
                fontSize="64" />
    </mx:VBox>

</mx:Application>

Due to popular demand, here is the “same” example in a more ActionScript friendly format:

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/09/24/displaying-a-drop-shadow-behind-a-vbox-container-in-flex/ -->
<mx:Application name="VBox_dropShadowEnabled_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        initialize="init();">

    <mx:Script>
        <![CDATA[
            import mx.controls.Label;
            import mx.containers.VBox;

            private var vBox:VBox;

            private function init():void {
                var lbl:Label = new Label();
                lbl.text = Capabilities.version;
                lbl.setStyle("fontSize", 64);

                vBox = new VBox();
                vBox.setStyle("dropShadowEnabled", true);
                vBox.setStyle("borderStyle", "solid");
                vBox.setStyle("borderThickness", 0);
                vBox.setStyle("backgroundColor", "red");
                vBox.percentWidth = 100;
                vBox.percentHeight = 100;
                vBox.addChild(lbl);
                addChild(vBox);
            }
        ]]>
    </mx:Script>

</mx:Application>
 
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 Displaying a drop shadow behind a VBox container in Flex

  1. dora says:

    Thanks for the tutorial. If you want generate drop shadow you can use this tool: http://www.dropshadowz.net/

  2. Ligl says:

    Thanks.
    Happy Flexing…

  3. Krishna says:

    Hi,
    Please reply to this post ….
    I have one array list will be loaded using HttpService. I have one Vbox component. In that I have 4 images. Based on the size of the array I need to show these images. I am not getting which event to catch to know the value of array as most of the I am getting array as null
    Regards,
    Krishna