The following example shows how you can disable/enable the play/pause button on the Spark VideoPlayer control in Flex 4 by setting the enabled property on the VideoPlayer control’s playPauseButton skin part.

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" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2009/05/13/disabling-the-playpause-button-on-the-spark-videoplayer-control-in-flex-gumbo/ -->
<s:Application name="Spark_VideoPlayer_playPauseButton_enabled_test"
        xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/halo">

    <fx:Script>
        <![CDATA[
            private function checkBox_change(evt:Event):void {
                videoPlayer.playPauseButton.enabled = checkBox.selected;
            }
        ]]>
    </fx:Script>

    <mx:ApplicationControlBar dock="true" width="100%" cornerRadius="0">
        <s:CheckBox id="checkBox"
                label="playPauseButton enabled"
                selected="true"
                change="checkBox_change(event);" />
    </mx:ApplicationControlBar>

    <s:VideoPlayer id="videoPlayer"
            source="http://helpexamples.com/flash/video/water.flv"
            autoRewind="true"
            muted="true"
            horizontalCenter="0"
            verticalCenter="0" />

</s:Application>

View source is enabled in the following example.

Due to popular demand, here is the “same” example in a more ActionScript friendly format:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2009/05/13/disabling-the-playpause-button-on-the-spark-videoplayer-control-in-flex-gumbo/ -->
<s:Application name="Spark_VideoPlayer_playPauseButton_enabled_test"
        xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/halo"
        initialize="init();">

    <fx:Script>
        <![CDATA[
            import mx.containers.ApplicationControlBar;
            import spark.components.VideoPlayer;
            import spark.components.CheckBox;

            private var checkBox:CheckBox;
            private var videoPlayer:VideoPlayer;

            private function init():void {
                checkBox = new CheckBox();
                checkBox.label = "playPauseButton enabled";
                checkBox.selected = true;
                checkBox.addEventListener(Event.CHANGE, checkBox_change);

                var appControlBar:ApplicationControlBar = new ApplicationControlBar();
                appControlBar.dock = true;
                appControlBar.percentWidth = 100;
                appControlBar.setStyle("cornerRadius", 0);
                appControlBar.addChild(checkBox);
                addElementAt(appControlBar, 0);

                videoPlayer = new VideoPlayer();
                videoPlayer.source = "http://helpexamples.com/flash/video/water.flv";
                videoPlayer.autoRewind = true;
                videoPlayer.muted = true;
                videoPlayer.horizontalCenter = 0;
                videoPlayer.verticalCenter = 0;
                addElement(videoPlayer);
            }

            private function checkBox_change(evt:Event):void {
                videoPlayer.playPauseButton.enabled = checkBox.selected;
            }
        ]]>
    </fx:Script>

</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.

 
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.

3 Responses to Disabling the play/pause button on the Spark VideoPlayer control in Flex 4

  1. it would be logical to disable the scrub/scroll bar too when disabling the play/pause button, no?

    thanx for the example.

  2. scott says:

    If I visit a site showing a flash video with a disabled play button, how can I stop the video without closing the site?

    • Peter deHaan says:

      @scott,

      You probably wouldn’t be able to, unless the developer added another method (custom context menu, for example) to play/pause the video. I wasn’t imaging building a YouTube or Hulu type site where users wouldn’t be able to pause a video, I was thinking more of how Hulu and other sites sometimes disable the ability to pause an advertisement or something.

      Peter

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