Setting the background alpha on a VideoDisplay control in Flex

In a previous example, “Setting the background color on a VideoDisplay control in Flex”, we saw how you could modify the background color of a VideoDisplay control in Flex by setting the backgroundColor style.

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

Full code after the jump.

View MXML

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

    <mx:Script>
        <![CDATA[
            private function loadButton_click(evt:MouseEvent):void {
                var url:String = "http://www.helpexamples.com/flash/video/clouds.flv";
                videoDisplay.source = url;
            }

            private function unloadButton_click(evt:MouseEvent):void {
                videoDisplay.close();
                videoDisplay.source = null;
                videoDisplay.mx_internal::videoPlayer.clear();
            }
        ]]>
    </mx:Script>

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

    <mx:VideoDisplay id="videoDisplay"
            backgroundAlpha="{slider.value}"
            backgroundColor="{colorPicker.selectedColor}"
            width="160"
            height="120" />

    <mx:ControlBar>
        <mx:Button id="loadButton"
                label="Load"
                click="loadButton_click(event);" />
        <mx:Button id="unloadButton"
                label="Unload"
                click="unloadButton_click(event);" />
    </mx:ControlBar>

</mx:Application>

View source is enabled in the following example.

0 thoughts on “Setting the background alpha on a VideoDisplay control in Flex