Packageflash.media
Classpublic class Video
InheritanceVideo Inheritance DisplayObject Inheritance EventDispatcher Inheritance Object

Language version: ActionScript 3.0
Runtime version: 

The Video class displays live or recorded video in an application without embedding the video in your SWF file. This class creates a Video object that plays either of the following kinds of video: recorded video files stored on a server or locally, or live video captured by the user. A Video object is a display object on the application's display list and represents the visual space in which the video runs in a user interface.

When used with Flash Media Server, the Video object allows you to send live video captured by a user to the server and then broadcast it from the server to other users. Using these features, you can develop media applications such as a simple video player, a video player with multipoint publishing from one server to another, or a video sharing application for a user community.

Flash Player 9 and later supports publishing and playback of FLV files encoded with either the Sorenson Spark or On2 VP6 codec and also supports an alpha channel. The On2 VP6 video codec uses less bandwidth than older technologies and offers additional deblocking and deringing filters. See the flash.net.NetStream class for more information about video playback and supported formats.

Flash Player 9.0.115.0 and later supports mipmapping to optimize runtime rendering quality and performance. For video playback, Flash Player uses mipmapping optimization if you set the Video object's smoothing property to true.

Beginning with AIR 25, a new tag has been introduced for Android in app.xml named disableMediaCodec. Setting this tag as true disables mediacodec and the video is decoded using OpenMax AL. Otherwise, mediacodec is enabled. The value of this tag is false, by default.

As with other display objects on the display list, you can control various properties of Video objects. For example, you can move the Video object around on the Stage by using its x and y properties, you can change its size using its height and width properties, and so on.

To play a video stream, use attachCamera() or attachNetStream() to attach the video to the Video object. Then, add the Video object to the display list using addChild().

If you are using Flash Professional, you can also place the Video object on the Stage rather than adding it with addChild(), like this:

  1. If the Library panel isn't visible, select Window > Library to display it.
  2. Add an embedded Video object to the library by clicking the Options menu on the right side of the Library panel title bar and selecting New Video.
  3. In the Video Properties dialog box, name the embedded Video object for use in the library and click OK.
  4. Drag the Video object to the Stage and use the Property Inspector to give it a unique instance name, such as my_video. (Do not name it Video.)

In AIR applications on the desktop, playing video in fullscreen mode disables any power and screen saving features (when allowed by the operating system).

Note: The Video class is not a subclass of the InteractiveObject class, so it cannot dispatch mouse events. However, you can call the addEventListener() method on the display object container that contains the Video object.

View the examples.

See also

attachCamera()
attachNetStream()
flash.media.Camera.getCamera()
flash.net.NetConnection
flash.net.NetStream
flash.display.DisplayObjectContainer.addChild()
flash.display.Stage.addChild()
Working with Video


Public Properties
 PropertyDefined by
 InheritedaccessibilityProperties : AccessibilityProperties
The current accessibility options for this display object.
DisplayObject
 Inheritedalpha : Number
Indicates the alpha transparency value of the object specified.
DisplayObject
 InheritedblendMode : String
A value from the BlendMode class that specifies which blend mode to use.
DisplayObject
 InheritedblendShader : Shader
Sets a shader that is used for blending the foreground and background.
DisplayObject
 InheritedcacheAsBitmap : Boolean
If set to true, Flash runtimes cache an internal bitmap representation of the display object.
DisplayObject
 InheritedcacheAsBitmapMatrix : Matrix
If non-null, this Matrix object defines how a display object is rendered when cacheAsBitmap is set to true.
DisplayObject
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
  deblocking : int
Indicates the type of filter applied to decoded video as part of post-processing.
Video
 Inheritedfilters : Array
An indexed array that contains each filter object currently associated with the display object.
DisplayObject
 Inheritedheight : Number
Indicates the height of the display object, in pixels.
DisplayObject
 InheritedloaderInfo : LoaderInfo
Returns a LoaderInfo object containing information about loading the file to which this display object belongs.
DisplayObject
 Inheritedmask : DisplayObject
The calling display object is masked by the specified mask object.
DisplayObject
 InheritedmetaData : Object
Obtains the meta data object of the DisplayObject instance if meta data was stored alongside the the instance of this DisplayObject in the SWF file through a PlaceObject4 tag.
DisplayObject
 InheritedmouseX : Number
Indicates the x coordinate of the mouse or user input device position, in pixels.
DisplayObject
 InheritedmouseY : Number
Indicates the y coordinate of the mouse or user input device position, in pixels.
DisplayObject
 Inheritedname : String
Indicates the instance name of the DisplayObject.
DisplayObject
 InheritedopaqueBackground : Object
Specifies whether the display object is opaque with a certain background color.
DisplayObject
 Inheritedparent : DisplayObjectContainer
Indicates the DisplayObjectContainer object that contains this display object.
DisplayObject
 Inheritedprototype : Object
[static] A reference to the prototype object of a class or function object.
Object
 Inheritedroot : DisplayObject
For a display object in a loaded SWF file, the root property is the top-most display object in the portion of the display list's tree structure represented by that SWF file.
DisplayObject
 Inheritedrotation : Number
Indicates the rotation of the DisplayObject instance, in degrees, from its original orientation.
DisplayObject
 InheritedrotationX : Number
Indicates the x-axis rotation of the DisplayObject instance, in degrees, from its original orientation relative to the 3D parent container.
DisplayObject
 InheritedrotationY : Number
Indicates the y-axis rotation of the DisplayObject instance, in degrees, from its original orientation relative to the 3D parent container.
DisplayObject
 InheritedrotationZ : Number
Indicates the z-axis rotation of the DisplayObject instance, in degrees, from its original orientation relative to the 3D parent container.
DisplayObject
 Inheritedscale9Grid : Rectangle
The current scaling grid that is in effect.
DisplayObject
 InheritedscaleX : Number
Indicates the horizontal scale (percentage) of the object as applied from the registration point.
DisplayObject
 InheritedscaleY : Number
Indicates the vertical scale (percentage) of an object as applied from the registration point of the object.
DisplayObject
 InheritedscaleZ : Number
Indicates the depth scale (percentage) of an object as applied from the registration point of the object.
DisplayObject
 InheritedscrollRect : Rectangle
The scroll rectangle bounds of the display object.
DisplayObject
  smoothing : Boolean
Specifies whether the video should be smoothed (interpolated) when it is scaled.
Video
 Inheritedstage : Stage
The Stage of the display object.
DisplayObject
 Inheritedtransform : Transform
An object with properties pertaining to a display object's matrix, color transform, and pixel bounds.
DisplayObject
  videoHeight : int
[read-only] An integer specifying the height of the video stream, in pixels.
Video
  videoWidth : int
[read-only] An integer specifying the width of the video stream, in pixels.
Video
 Inheritedvisible : Boolean
Whether or not the display object is visible.
DisplayObject
 Inheritedwidth : Number
Indicates the width of the display object, in pixels.
DisplayObject
 Inheritedx : Number
Indicates the x coordinate of the DisplayObject instance relative to the local coordinates of the parent DisplayObjectContainer.
DisplayObject
 Inheritedy : Number
Indicates the y coordinate of the DisplayObject instance relative to the local coordinates of the parent DisplayObjectContainer.
DisplayObject
 Inheritedz : Number
Indicates the z coordinate position along the z-axis of the DisplayObject instance relative to the 3D parent container.
DisplayObject
Public Methods
 MethodDefined by
  
Video(width:int = 320, height:int = 240)
Creates a new Video instance.
Video
 Inherited
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
Registers an event listener object with an EventDispatcher object so that the listener receives notification of an event.
EventDispatcher
  
Specifies a video stream from a camera to be displayed within the boundaries of the Video object in the application.
Video
  
Specifies a video stream to be displayed within the boundaries of the Video object in the application.
Video
  
Clears the image currently displayed in the Video object (not the video stream).
Video
 Inherited
Dispatches an event into the event flow.
EventDispatcher
 Inherited
getBounds(targetCoordinateSpace:DisplayObject):Rectangle
Returns a rectangle that defines the area of the display object relative to the coordinate system of the targetCoordinateSpace object.
DisplayObject
 Inherited
getRect(targetCoordinateSpace:DisplayObject):Rectangle
Returns a rectangle that defines the boundary of the display object, based on the coordinate system defined by the targetCoordinateSpace parameter, excluding any strokes on shapes.
DisplayObject
 Inherited
Converts the point object from the Stage (global) coordinates to the display object's (local) coordinates.
DisplayObject
 Inherited
Converts a two-dimensional point from the Stage (global) coordinates to a three-dimensional display object's (local) coordinates.
DisplayObject
 Inherited
Checks whether the EventDispatcher object has any listeners registered for a specific type of event.
EventDispatcher
 Inherited
Indicates whether an object has a specified property defined.
Object
 Inherited
Evaluates the bounding box of the display object to see if it overlaps or intersects with the bounding box of the obj display object.
DisplayObject
 Inherited
hitTestPoint(x:Number, y:Number, shapeFlag:Boolean = false):Boolean
Evaluates the display object to see if it overlaps or intersects with the point specified by the x and y parameters.
DisplayObject
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
 Inherited
Converts a three-dimensional point of the three-dimensional display object's (local) coordinates to a two-dimensional point in the Stage (global) coordinates.
DisplayObject
 Inherited
Converts the point object from the display object's (local) coordinates to the Stage (global) coordinates.
DisplayObject
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
 Inherited
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
Removes a listener from the EventDispatcher object.
EventDispatcher
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
 Inherited
Returns the string representation of this object, formatted according to locale-specific conventions.
Object
 Inherited
Returns the string representation of the specified object.
Object
 Inherited
Returns the primitive value of the specified object.
Object
 Inherited
Checks whether an event listener is registered with this EventDispatcher object or any of its ancestors for the specified event type.
EventDispatcher
Events
 EventSummaryDefined by
 Inherited [broadcast event] Dispatched when the Flash Player or AIR application gains operating system focus and becomes active.EventDispatcher
 Inherited Dispatched when a display object is added to the display list.DisplayObject
 Inherited Dispatched when a display object is added to the on stage display list, either directly or through the addition of a sub tree in which the display object is contained.DisplayObject
 Inherited [broadcast event] Dispatched when the Flash Player or AIR application operating loses system focus and is becoming inactive.EventDispatcher
 Inherited [broadcast event] Dispatched when the playhead is entering a new frame.DisplayObject
 Inherited [broadcast event] Dispatched when the playhead is exiting the current frame.DisplayObject
 Inherited [broadcast event] Dispatched after the constructors of frame display objects have run but before frame scripts have run.DisplayObject
 Inherited Dispatched when a display object is about to be removed from the display list.DisplayObject
 Inherited Dispatched when a display object is about to be removed from the display list, either directly or through the removal of a sub tree in which the display object is contained.DisplayObject
 Inherited [broadcast event] Dispatched when the display list is about to be updated and rendered.DisplayObject
Property detail
deblockingproperty
deblocking:int  [read-write]

Language version: ActionScript 3.0
Runtime version: 

Indicates the type of filter applied to decoded video as part of post-processing. The default value is 0, which lets the video compressor apply a deblocking filter as needed.

Compression of video can result in undesired artifacts. You can use the deblocking property to set filters that reduce blocking and, for video compressed using the On2 codec, ringing.

Blocking refers to visible imperfections between the boundaries of the blocks that compose each video frame. Ringing refers to distorted edges around elements within a video image.

Two deblocking filters are available: one in the Sorenson codec and one in the On2 VP6 codec. In addition, a deringing filter is available when you use the On2 VP6 codec. To set a filter, use one of the following values:

If a value greater than 2 is selected for video when you are using the Sorenson codec, the Sorenson decoder defaults to 2.

Using a deblocking filter has an effect on overall playback performance, and it is usually not necessary for high-bandwidth video. If a user's system is not powerful enough, the user may experience difficulties playing back video with a deblocking filter enabled.

Implementation
    public function get deblocking():int
    public function set deblocking(value:int):void
smoothingproperty 
smoothing:Boolean  [read-write]

Language version: ActionScript 3.0
Runtime version: 

Specifies whether the video should be smoothed (interpolated) when it is scaled. For smoothing to work, the runtime must be in high-quality mode (the default). The default value is false (no smoothing).

For video playback using Flash Player 9.0.115.0 and later versions, set this property to true to take advantage of mipmapping image optimization.

Implementation
    public function get smoothing():Boolean
    public function set smoothing(value:Boolean):void
videoHeightproperty 
videoHeight:int  [read-only]

Language version: ActionScript 3.0
Runtime version: 

An integer specifying the height of the video stream, in pixels. For live streams, this value is the same as the Camera.height property of the Camera object that is capturing the video stream. For recorded video files, this value is the height of the video. The NetStream.Video.DimensionChange event is dispatched in the case of recorded videos when this value changes.

You may want to use this property, for example, to ensure that the user is seeing the video at the same size at which it was captured, regardless of the actual size of the Video object on the Stage.

Implementation
    public function get videoHeight():int

See also

videoWidthproperty 
videoWidth:int  [read-only]

Language version: ActionScript 3.0
Runtime version: 

An integer specifying the width of the video stream, in pixels. For live streams, this value is the same as the Camera.width property of the Camera object that is capturing the video stream. For recorded video files, this value is the width of the video. The NetStream.Video.DimensionChange event is dispatched in the case of recorded videos when this value changes.

You may want to use this property, for example, to ensure that the user is seeing the video at the same size at which it was captured, regardless of the actual size of the Video object on the Stage.

Implementation
    public function get videoWidth():int

See also

Constructor detail
Video()constructor
public function Video(width:int = 320, height:int = 240)

Language version: ActionScript 3.0
Runtime version: 

Creates a new Video instance. If no values for the width and height parameters are supplied, the default values are used. You can also set the width and height properties of the Video object after the initial construction, using Video.width and Video.height. When a new Video object is created, values of zero for width or height are not allowed; if you pass zero, the defaults will be applied.

After creating the Video, call the DisplayObjectContainer.addChild() or DisplayObjectContainer.addChildAt() method to add the Video object to a parent DisplayObjectContainer object.

Parameters
width:int (default = 320) — The width of the video, in pixels.
 
height:int (default = 240) — The height of the video, in pixels.

Example
The following example shows how to load an external FLV file:
var MyVideo:Video = new Video();
addChild(MyVideo);
 
var MyNC:NetConnection = new NetConnection();
MyNC.connect(null);
 
var MyNS:NetStream = new NetStream(MyNC);
MyNS.play("http://www.helpexamples.com/flash/video/clouds.flv");

MyVideo.attachNetStream(MyNS);

//the clouds.flv video has metadata we're not using, so create
//an error handler to ignore the message generated by the runtime
//about the metadata
MyNS.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler); 

function asyncErrorHandler(event:AsyncErrorEvent):void 
{ 
   //ignore metadata error message
}

Method detail
attachCamera()method
public function attachCamera(camera:Camera):void

Language version: ActionScript 3.0
Runtime version: 

Specifies a video stream from a camera to be displayed within the boundaries of the Video object in the application.

Use this method to attach live video captured by the user to the Video object. You can play the live video locally on the same computer or device on which it is being captured, or you can send it to Flash Media Server and use the server to stream it to other users.

Note: In an iOS AIR application, camera video cannot be displayed when the application uses GPU rendering mode.

Parameters
camera:Camera — A Camera object that is capturing video data. To drop the connection to the Video object, pass null.

See also


Example

attachNetStream()method 
public function attachNetStream(netStream:NetStream):void

Language version: ActionScript 3.0
Runtime version: 

Specifies a video stream to be displayed within the boundaries of the Video object in the application. The video stream is either a video file played with NetStream.play(), a Camera object, or null. If you use a video file, it can be stored on the local file system or on Flash Media Server. If the value of the netStream argument is null, the video is no longer played in the Video object.

You do not need to use this method if a video file contains only audio; the audio portion of video files is played automatically when you call NetStream.play(). To control the audio associated with a video file, use the soundTransform property of the NetStream object that plays the video file.

Parameters
netStream:NetStream — A NetStream object. To drop the connection to the Video object, pass null.

See also


Example

clear()method 
public function clear():void

Language version: ActionScript 3.0
Runtime version: 

Clears the image currently displayed in the Video object (not the video stream). This method is useful for handling the current image. For example, you can clear the last image or display standby information without hiding the Video object.

See also

Examples
examples\VideoExample
The following example uses a Video object with the NetConnection and NetStream classes to load and play an FLV file. To run this example, you need an FLV file whose name and location match the variable passed to videoURL, in this case, an FLV file called Video.flv that is in the same directory as the SWF file.

In this example, the code that creates the Video and NetStream objects and calls Video.attachNetStream() and NetStream.play() is placed in a handler function. The handler is called only if the attempt to connect to the NetConnection object is successful, which is when the netStatus event returns an info object with a code property that indicates success. It is recommended that you wait for a successful connection before calling NetStream.play().


 package {
    import flash.display.Sprite;
    import flash.events.*;
    import flash.media.Video;
    import flash.net.NetConnection;
    import flash.net.NetStream;

    public class VideoExample extends Sprite {
        private var videoURL:String = "Video.flv";
        private var connection:NetConnection;
        private var stream:NetStream;

        public function VideoExample() {
            connection = new NetConnection();
            connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
            connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
            connection.connect(null);
        }

        private function netStatusHandler(event:NetStatusEvent):void {
            switch (event.info.code) {
                case "NetConnection.Connect.Success":
                    connectStream();
                    break;
                case "NetStream.Play.StreamNotFound":
                    trace("Unable to locate video: " + videoURL);
                    break;
            }
        }

        private function connectStream():void {
            stream = new NetStream(connection);
            stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
            stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
            var video:Video = new Video();
            video.attachNetStream(stream);
            stream.play(videoURL);
            addChild(video);
        }

        private function securityErrorHandler(event:SecurityErrorEvent):void {
            trace("securityErrorHandler: " + event);
        }
        
        private function asyncErrorHandler(event:AsyncErrorEvent):void {
            // ignore AsyncErrorEvent events.
        }
    }
 }