Clearing the video on a Spark VideoElement control in Flex 4

In a previous example, “Clearing the video on a Flex VideoDisplay control”, we saw how you could clear a VideoDisplay control’s content using the videoPlayer property in the mx_internal namespace.

The following example shows how you can clear a Spark VideoElement control’s video stream in a Flex 4 application by calling the clear() method on the VideoElement instance’s videoObject property.

Full code after the jump.

The following example(s) require Flash Player 10 and the Adobe Flex 4 SDK. To download the Adobe Flash Builder 4 trial, see www.adobe.com/products/flex/. To download the latest nightly build of the Flex 4 SDK, see opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4.

For more information on getting started with Flex 4 and Flash Builder 4, see the official Adobe Flex Team blog.

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2009/10/22/clearing-the-video-on-a-spark-videoelement-control-in-flex-4/ -->
<s:Application name="Spark_VideoElement_clear_test"
        xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark">
    <s:controlBarContent>
        <s:Button id="btn"
                label="clear video"
                click="btn_clickHandler(event)" />
    </s:controlBarContent>
 
    <fx:Script>
        <![CDATA[
            protected function btn_clickHandler(evt:MouseEvent):void{
                if (vdElmnt.playing) {
                    vdElmnt.pause();
                }
                vdElmnt.videoObject.clear();
            }
        ]]>
    </fx:Script>
 
    <s:VideoElement id="vdElmnt"
            source="http://helpexamples.com/flash/video/water.flv"
            horizontalCenter="0" verticalCenter="0" />
 
</s:Application>

This entry is based on a beta version of the Flex 4 SDK and therefore is very likely to change as development of the Flex SDK continues. The API can (and will) change causing examples to possibly not compile in newer versions of the Flex 4 SDK.