Displaying a video in a pop up window in Flex

by Peter deHaan on August 4, 2008

The following example shows how you can use the PopUpManager class to display a VideoDisplay control in a TitleWindow container in Flex.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/08/04/displaying-a-video-in-a-pop-up-window-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="top"
        backgroundColor="white">

    <mx:Script>
        <![CDATA[
            import mx.managers.PopUpManager;

            private function button_click(evt:MouseEvent):void {
                var popUpVideoDisplay:PopUpVideoDisplay;
                popUpVideoDisplay = new PopUpVideoDisplay();
                popUpVideoDisplay.source = "http://www.helpexamples.com/flash/video/water.flv";
                PopUpManager.addPopUp(popUpVideoDisplay, this, true);
            }
        ]]>
    </mx:Script>

    <mx:Button id="button"
            label="Launch video"
            click="button_click(event);" />

</mx:Application>

PopUpVideoDisplay.mxml

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/08/04/displaying-a-video-in-a-pop-up-window-in-flex/ -->
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml"
        showCloseButton="true"
        styleName="noPadding"
        creationComplete="init();"
        close="titleWindow_close(event);">

    <mx:Style>
        .noPadding {
            paddingBottom: 0;
            paddingTop: 0;
            paddingLeft: 0;
            paddingRight: 0;
        }
    </mx:Style>

    <mx:Script>
        <![CDATA[
            import mx.managers.IFocusManagerComponent;
            import mx.controls.Alert;
            import mx.core.IFlexDisplayObject;
            import mx.events.CloseEvent;
            import mx.managers.PopUpManager;

            [Bindable]
            public var source:String;

            private function init():void {
                PopUpManager.centerPopUp(this);
            }

            private function titleWindow_close(evt:CloseEvent):void {
                PopUpManager.removePopUp(evt.target as IFlexDisplayObject);
            }
        ]]>
    </mx:Script>

    <mx:VideoDisplay id="videoDisplay"
            source="{source}"
            resize="init();" />

    <mx:ControlBar horizontalAlign="right" width="100%">
    </mx:ControlBar>

</mx:TitleWindow>

View source is enabled in the following example.

{ 12 comments… read them below or add one }

Blenjar August 4, 2008 at 4:08 pm

Thats sick!

Reply

MechanisM August 9, 2008 at 7:35 am

did anybody seen any good example of SWFAddress??gimme da links please?

Reply

rahul September 23, 2008 at 10:58 pm

HI well there is a bug here……the moment you keep pressing space bar…new window will load automtaiclly……can you resolve this

Reply

Abhilash November 17, 2008 at 9:56 pm

I have a form designed using Flex. The form does not fit the screen area and hence I am having scroll bars in it. When we click on some of the controls in the form, we open popups. But when the popup is opened, if we scroll the form using the form scroll bar then the popup is not getting scrolled. I want the popup to be scrolled along with the form elements. Please let me know how this can be done.

Thanks

Abhilash

Reply

Peter deHaan March 20, 2009 at 3:46 pm

ScottyG,

Oops.
The best fix is probably calling the stop() method on the VideoDisplay control when the PopUp window is closed.

Peter

Reply

S.Jaiganesh October 15, 2009 at 9:41 pm
 
It's Amazing One

Reply

Rod November 19, 2009 at 3:40 am

If you use the close on the popup window the sound continues to play!

Reply

Peter deHaan November 22, 2009 at 12:34 pm

@Rod,

Correct. Sorry, I should have explicitly called the stop() method in the close handler before removing the popup from the display list.

Peter

Reply

ismael December 17, 2009 at 6:32 pm

videoDisplay.close();

Reply

xabibi January 21, 2010 at 2:31 am

I want controls to play, pause, stop the video. Is it possible in this example?

Reply

Peter deHaan January 21, 2010 at 7:38 am

@xabibi,

Sure, in the PopUpVideoDisplay.mxml ControlBar, just add a few mx:Button controls that play, pause, stop the video.

Peter

Reply

Apoorv July 2, 2010 at 2:18 am

Hey peter ,
Can this example be used to display the live stream ??

Apoorv

Reply

Leave a Comment

Sorry, this blog is terrible at eating HTML comments.
If you're pasting any HTML/XML/MXML code, you need to convert your < characters to &lt; and your > characters to &gt; .

Anti-Spam Protection by WP-SpamFree

Previous post:

Next post: