Clearing the video on a Flex VideoDisplay control
I posted this in response to a forum question the other day and thought I’d share the code here.
The following example shows you how you can clear a VideoDisplay control’s content using the videoPlayer property in the mx_internal namespace.
Full code after the jump.
Option 1: Call the videoDisplay.mx_internal::videoPlayer.clear() method directly from our MXML file:
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/01/15/clearing-the-video-on-a-flex-videodisplay-control/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical">
<mx:VideoDisplay id="videoDisplay"
source="http://www.helpexamples.com/flash/video/cuepoints.flv" />
<mx:Button label="pause"
click="videoDisplay.pause();" />
<mx:Button label="clear"
click="videoDisplay.mx_internal::videoPlayer.clear();" />
</mx:Application>
View source is enabled in the following example.
Option 2: Extend the VideoDisplay class in ActionScript, and add a custom clear() method which calls the mx_internal::videoPlayer.clear() method:
package {
import mx.controls.VideoDisplay;
import mx.core.mx_internal;
public class MyVideoDisplay extends VideoDisplay {
public function MyVideoDisplay() {
super();
}
public function clear():void {
pause();
mx_internal::videoPlayer.clear();
}
}
}
Then, in our MXML file, we simply add our MyVideoDisplay custom component and call our clear() method directly:
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/01/15/clearing-the-video-on-a-flex-videodisplay-control/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:custom="*"
layout="vertical">
<custom:MyVideoDisplay id="myVideoDisplay"
source="http://www.helpexamples.com/flash/video/cuepoints.flv" />
<mx:Button label="clear"
click="myVideoDisplay.clear();" />
</mx:Application>
Option 3: Create a custom component in MXML that extends the VideoDisplay control. Again, we add our own custom clear() method which calls the mx_internal::videoPlayer.clear() method:
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/01/15/clearing-the-video-on-a-flex-videodisplay-control/ -->
<mx:VideoDisplay xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.core.mx_internal;
public function clear():void {
pause();
mx_internal::videoPlayer.clear();
}
]]>
</mx:Script>
</mx:VideoDisplay>
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.
-
Add Widgets (Content Sidebar)
This is your Content Sidebar. Edit this content that appears here in the widgets panel by adding or removing widgets in the Content Sidebar area.
20 Responses to Clearing the video on a Flex VideoDisplay control
Leave a Reply Cancel reply
-
Categories
- Accordion
- AccordionHeader
- ActionScript
- AddChild
- AdvancedDataGrid
- Alert
- alpha
- Animate
- AnimateProperties
- Application
- Application (Spark)
- ArrayCollection
- BarChart
- baseColor
- beta
- beta1
- beta2
- Bitmap
- Bitmap/BitmapData
- BitmapData
- BitmapFill
- BitmapFill (Spark)
- BitmapGraphic
- BitmapImage
- BitmapImage (Spark)
- BitmapImageResizeMode
- Border (Spark)
- BorderContainer (Spark)
- Box
- BuildInfo
- Button
- Button (Spark)
- ButtonBar
- ButtonBar (Spark)
- ByteArray
- Camera
- Charting
- CheckBox
- CheckBox (Spark)
- ClassFactory
- CollectionEvent
- Color
- ColorPicker
- ColorUtil
- ComboBox
- ComboBoxArrowSkin
- Compiler
- Component
- Component (Spark)
- Configuration
- Container
- ContextMenu
- ContextMenuEvent
- ContextMenuItem
- CSSCondition
- CSSSelector
- CSSStyleDeclaration
- CurrencyFormatter
- CursorManager
- Data Binding
- DataGrid
- DataGrid (Spark)
- DataGridColumn
- Date
- DateBase
- DateChooser
- DateField
- DateFormatter
- Debugging
- DefaultComplexItemRenderer
- DefaultTileListEffect
- DropDownList
- DropDownList (Spark)
- DropDownListButtonSkin
- DropDownListSkin
- DropShadowFilter
- E4X
- Effects
- Ellipse
- EmailValidator
- Embed
- Event
- Fade
- FileFilter
- FileReference
- fill
- Filters
- Flash
- Flash Integration
- FlashVars
- Flex 3 SDK
- Flex Builder
- Flex Builder 3
- Flex SDK
- Flex4
- FLVPlayback
- FocusManager
- FontLookup
- Fonts
- Form
- Form (Spark)
- FormHeading (Spark)
- FormItem
- FormItem (Spark)
- Forms
- FTETextField (Spark)
- FullScreen
- FullScreenEvent
- FxAnimateColor
- FxButtonBar
- FxCheckBox
- FXG
- FxHScrollBar
- FxHSlider
- FxList
- FxNumericStepper
- FxRadioButton
- FxRotate3D
- FxScroller
- FxTextArea
- FxTextInput
- FxToggleButton
- FxVScrollBar
- FxVSlider
- getStyleDeclaration()
- GradientEntry
- Graphic (Spark)
- HBox
- HDividedBox
- HGroup (Spark)
- HorizontalLayout
- HorizontalList
- HSBColor (Spark)
- HScrollBar (Spark)
- HSlider
- HSlider (Spark)
- HTML template
- ID3Info
- Image
- Image (Spark)
- ImageSnapshot
- itemRenderer
- JointStyle
- Label
- Label (Spark)
- Legend
- LegendItem
- LigatureLevel
- Line
- LinearGradientStroke
- LineScaleMode
- LinkBar
- LinkButton
- List
- List (Spark)
- Menu
- MenuBar
- Metadata
- MetadataEvent
- Model
- Mouse
- MouseCursor
- MouseEvent
- Move
- Namespace
- NavigatorContent (Spark)
- needsSWF
- NetConnection
- NetStream
- Nightly Builds
- NumberBaseRoundType
- NumberFormatter
- NumberValidator
- NumericCompare
- NumericStepper
- NumericStepper (Spark)
- ObjectProxy
- ObjectUtil
- paddingLeft
- paddingRight
- Panel
- Panel (Spark)
- Parallel
- Path
- PieChart
- PieSeries
- PieSeriesItem
- PopUpAnchor (Spark)
- PopUpButton
- PopUpManager
- ProgrammaticSkin
- ProgressBar
- PropertyChangeEvent
- QName
- RadialGradient
- RadioButton
- RadioButton (Spark)
- RadioButtonGroup
- RadioButtonGroup (Spark)
- Rect
- RegExp
- Regular Expressions
- Repeater
- RichEditableText
- RichText
- RichText (Spark)
- RichTextEditor
- Rotate
- Rotate3D (Spark)
- Scroller (Spark)
- Sequence
- setStyle()
- SimpleText
- SimpleText (Spark)
- skinClass
- Slider
- SliderEvent
- SolidColor
- SolidColorStroke
- Sort
- SortField
- Sound
- SoundEffect
- Spinner (Spark)
- SpriteVisualElement (Spark)
- StageDisplayState
- States
- StringUtil
- StringValidator
- StyleManager
- Styles
- SWFLoader
- SWFObject
- System
- SystemManager
- TabBar
- TabBar (Spark)
- TabNavigator
- TabStopFormat
- Text
- Text Layout Framework (TLF)
- TextArea
- TextArea (Spark)
- TextBox
- TextConverter
- TextEvent
- TextFlow
- TextFlowUtil
- TextFormat
- TextGraphic
- TextInput
- TextInput (Spark)
- TextLayoutFormat
- TextView
- Themes
- TileLayout
- TileList
- TileOrientation
- Timer
- TitleWindow
- TitleWindow (Spark)
- TLF
- ToggleButton (Spark)
- ToggleButtonBar
- ToolTip
- Transition
- Tree
- TruncationOptions
- UIComponent
- UIFTETextField
- Updater
- URLLoader
- URLRequest
- URLUtil
- URLVariables
- ValidationResultEvent
- Validator
- Validators
- VBox
- VDividedBox
- Vector
- VerticalLayout
- VerticalLayout (Spark)
- VGroup (Spark)
- Video
- VideoDisplay
- VideoElement
- VideoElement (Spark)
- VideoEvent
- VideoPlayer (Spark)
- VideoPlayerScrubBar
- ViewStack
- VScrollBar (Spark)
- VSlider
- VSlider (Spark)
- XML
- XMLList
- XMLListCollection
- ZipCodeValidator
- ZipCodeValidatorDomainType
- Zoom
-
Articles
- December 2010
- November 2010
- October 2010
- September 2010
- August 2010
- July 2010
- June 2010
- May 2010
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
-
Meta


Why don’t you have to use
use namespace mx_internal;
or better yet, when do I have to use that statement.
thanks for this tutorial btw. i was trying to clear a videodisplay yesterday.
adam,
Excellent tip! I totally forgot about the
use namespacesolution. It really could apply to any of the solutions above, but since pption 1 is probably the most easily copy-paste-able:Peter
very helped thank you
great video display control tips.
I may apply this tips on one of my site project.
thanks
This was a great find to be able to clear out the VideoDisplay object. However, I have found that when your video has been encoded with an alpha channel, this clear method does not work. Anyone have any ideas of why this method would not work with transparent video?
How to add volume control? Is it possible?
gustavo,
The VideoDisplay control has a
volumeproperty that you can set to a value between 0 and 1 which sets the volume.I can probably post an example in a couple minutes: “Setting the volume on a VideoDisplay control in Flex”.
Peter
peterd,
Thanks, thanks so much!
But, there is also a bug in Flash Player:
http://bugs.adobe.com/jira/browse/SDK-11262
Sometimes Video.clear not works as we expecting.
Hi Peter,
Great article. One question if you could help, please?
I am trying to play a flv file which is pushed from blazeDS server I am using Cairngorm/modelLocator to get the array of UploadVideo objects:
UploadVideo.as
public var videoName:String;
public var video:ByteArray;
in my mxml I declare a mx:List and assign the arrayCollection objects to my list’s dataProvider
videosOfStudents = ArrayCollection() // of UploadVideo objects
and this is my VideoDisplay component: (videoName is the name of the flv file)
When I click cntlDisp.play(); I get a following error:
(TypeError)#0
errorID = 1009
message = “Error #1009: Cannot access a property or method of a null object reference.”
but when I add a flv file locally it works fine.
Any idea?
Thanks.
Vardan
Hi Peter,
Sorry, some of my code did not appear properly because of the tags:
UploadVideo.as
public var videoName:String;
public var video:ByteArray;
videosOfStudents = ArrayCollection() // of UploadVideo objects
mx:List id=”cntlMovie” dataProvider=”{modelLocator.videosOfStudents}” width=”300″
mx:VideoDisplay id=”cntlDisp” source=”{cntlMovie.selectedItem.videoName}” width=”100%” height=”100%”
The output I get is:
(TypeError)#0
errorID = 1009
message = “Error #1009: Cannot access a property or method of a null object reference.”
Thanks again.
Vardan
This tip is not working perfectly, I recommend instead, in order to clear the video, to use the visible property (with a Fade effect is terrible!).
Moreover, use mx_internal stuff is not recommended since it can be remove for future versions of the framework.
——————————————————–
eBuildy, the web2.0 specialists!
Anyone know how to clear a videoDisplay that has been showing a live stream? .pause() does not seem to have any effect
@jerome,
If
clear()doesn’t work, maybe try setting a null source.Peter
setting a null source does not seem to have any effect either. I’m using a Video attached to a VideoDisplay (something like VideoDisplay.addChild(Video)
ok nevermind I got clear() working. I had to use .clear() on the Video object that was attached to the VideoDisplay
Hi Jerome.
Thanx for the idea, but in my code don´t work and I don´t now why.
My code is this
private function catchCam():void{
this._vid=new Video();
this._vid.width=320;
this._vid.height=240;
this.vd_Cam.addChild(this._vid);
this.cam=Camera.getCamera(this.cbCam.selectedIndex.toString());
if (!this.cam) {
this._vid.attachCamera(null);
this._vid.clear();
}else{
this._vid.attachCamera(this.cam);
}
}
note: vd_Cam it´s a videoDisplay Object.
The problem is that when execute
this._vid.attachCamera(null);
this._vid.clear();
The camera never deatach of the videoDisplay Object and never clear the videoDisplay Object. By the way debugging the code i´m sure that this sentences are executed.
Why is this happening to me?, any idea?
Thanx
Why don’t extend a UIComponent class to create a custom Video Component .. According to my personal opinion VideoDisplay component of Flex 3.5 sucks .
is it supported on Flex3?
because I copied the 1st example and paste but I got an error, it is not working!!
sir,
help me out please..
i am developing video chatting..using asp.net .
i am using fluorine fx streaming server.
iam going to integrate flex with asp.net….
can you guide me for my project…
i want to knoe how to set up the server…using iis..
thank you….