The following example shows how you can modify the background color of a Flex VideoDisplay control by setting the backgroundColor 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-color-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="backgroundColor:">
                <mx:ColorPicker id="colorPicker" />
            </mx:FormItem>
        </mx:Form>
    </mx:ApplicationControlBar>

    <mx:VideoDisplay id="videoDisplay"
            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.

You can also set the backgroundColor style in an external .CSS file or in an <mx:Style /> block, as seen in the following snippet:

<mx:Style>
    VideoDisplay {
        backgroundColor: red;
    }
</mx:Style>

Or, you could set the backgroundColor style using ActionScript, as seen in the following snippet:

videoDisplay.setStyle("backgroundColor", "red");
 
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.

One Response to Setting the background color on a VideoDisplay control in Flex

  1. eternalko says:

    he-he..
    Nice :)

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