The following example shows how you can rewind a Spark VideoPlayer control in Flex 4 when the selected MX Accordion container changes its selected item by listening for the hide event on the Spark NavigatorContent container and calling the seek() method on the VideoPlayer instance.

The following example(s) require Flash Player 10 and the Adobe Flex 4 SDK. To download the Adobe Flash Builder 4 trial, see http://www.adobe.com/products/flex/. To download the latest nightly build of the Flex 4 SDK, see http://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"?>
<!-- http://blog.flexexamples.com/2010/04/29/rewinding-a-video-when-changing-the-selected-item-in-the-mx-accordion-container-in-flex-4/ -->
<s:Application name="Spark_NavigatorContent_hide_test"
        xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/mx">
 
    <mx:Accordion id="acc"
            left="40" right="40" top="40" bottom="40">
        <s:NavigatorContent label="Video 1"
                width="100%" height="100%"
                hide="vidPlay1.seek(0);">
            <s:VideoPlayer id="vidPlay1"
                    source="http://helpexamples.com/flash/video/water.flv"
                    autoPlay="false"
                    left="0" right="0" top="0" bottom="0" />
        </s:NavigatorContent>
        <s:NavigatorContent label="Video 2"
                width="100%" height="100%"
                hide="vidPlay2.seek(0);">
            <s:VideoPlayer id="vidPlay2"
                    source="http://helpexamples.com/flash/video/clouds.flv"
                    autoPlay="false"
                    left="0" right="0" top="0" bottom="0" />
        </s:NavigatorContent>
        <s:NavigatorContent label="Video 3"
                width="100%" height="100%"
                hide="vidPlay3.seek(0);">
            <s:VideoPlayer id="vidPlay3"
                    source="http://helpexamples.com/flash/video/cuepoints.flv"
                    autoPlay="false"
                    left="0" right="0" top="0" bottom="0" />
        </s:NavigatorContent>
        <s:NavigatorContent label="Video 4"
                width="100%" height="100%"
                hide="vidPlay4.seek(0);">
            <s:VideoPlayer id="vidPlay4"
                    source="http://helpexamples.com/flash/video/caption_video.flv"
                    autoPlay="false"
                    left="0" right="0" top="0" bottom="0" />
        </s:NavigatorContent>
    </mx:Accordion>
 
</s:Application>

View source is enabled in the following example.

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.

 
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 Rewinding a video when changing the selected item in the MX Accordion container in Flex 4

  1. Igor Borodin says:

    Hello Peter,

    Incidentally, I’ve just made Accordion component that displays SWFs in each of its panels.
    Trying to minimize the size of the component, I made just one SWFLoader and upon ‘change’ event I unload the current swf, assign different ‘source’ to the SWFLoader, and then use ‘addElement’ to the selected panel (NavigatorContent).
    It works, but I wonder would there be any benefits to just creating an instance of SWFLoader for each panel as you show in your example with VideoPlayer?
    If my question sounds vague, I can attach the sample code.

    Thanks,
    Igor

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