30
Dec
08

Maintaining an video’s aspect ratio on a VideoDisplay control in Flex

The following example shows how you can maintain a loaded video’s original aspect ratio on a Flex VideoDisplay control by setting the maintainAspectRatio property.

Full code after the jump.

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/12/30/maintaining-an-videos-aspect-ratio-on-a-videodisplay-control-in-flex/ -->
<mx:Application name="VideoDisplay_maintainAspectRatio_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:ApplicationControlBar dock="true">
        <mx:Form styleName="plain">
            <mx:FormItem label="maintainAspectRatio:">
                <mx:CheckBox id="checkBox" />
            </mx:FormItem>
        </mx:Form>
    </mx:ApplicationControlBar>

    <mx:VideoDisplay id="videoDisplay"
            maintainAspectRatio="{checkBox.selected}"
            source="http://helpexamples.com/flash/video/cuepoints.flv"
            autoPlay="false"
            width="200"
            height="200"
            click="videoDisplay.play();" />

</mx:Application>

You can also set the maintainAspectRatio property using ActionScript, as seen in the following example:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/12/30/maintaining-an-videos-aspect-ratio-on-a-videodisplay-control-in-flex/ -->
<mx:Application name="VideoDisplay_maintainAspectRatio_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Script>
        <![CDATA[
            private function checkBox_change(evt:Event):void {
                videoDisplay.maintainAspectRatio = checkBox.selected;
            }
        ]]>
    </mx:Script>

    <mx:ApplicationControlBar dock="true">
        <mx:Form styleName="plain">
            <mx:FormItem label="maintainAspectRatio:">
                <mx:CheckBox id="checkBox"
                        selected="true"
                        change="checkBox_change(event);" />
            </mx:FormItem>
        </mx:Form>
    </mx:ApplicationControlBar>

    <mx:VideoDisplay id="videoDisplay"
            source="http://helpexamples.com/flash/video/cuepoints.flv"
            autoPlay="false"
            width="200"
            height="200"
            click="videoDisplay.play();" />

</mx:Application>

1 Response to “Maintaining an video's aspect ratio on a VideoDisplay control in Flex”


  1. 1 Dress Game Jan 3rd, 2009 at 9:55 am

    I like having the ability to change my video aspect ratio on the fly like in VLC media player.

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;".




Badge Farm

  • Powered by Redoable 1.2
  • Cornify
  • Feeds burnt by Feedburner
  • Feed