Adobe® Flex® 4 Language Reference
Show Packages and Classes List |  Packages  |  Classes  |  Index  |  Appendixes
flash.media 
Video 
Packageflash.media
Classpublic class Video
InheritanceVideo Inheritance DisplayObject Inheritance EventDispatcher Inheritance Object

Language Version: ActionScript 3.0
Runtime Versions: AIR 1.0 Flash Player 9, Flash Lite 4

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

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.

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

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



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
[write-only] 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
 InheritedAIR-only cacheAsBitmapMatrix : 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
[read-only] 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
 InheritedmouseX : Number
[read-only] Indicates the x coordinate of the mouse or user input device position, in pixels.
DisplayObject
 InheritedmouseY : Number
[read-only] 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
[read-only] 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
[read-only] 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
[read-only] The Stage of the display object.
DisplayObject
 Inheritedtransform : flash.geom: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
 Event Summary Defined By
 Inherited[broadcast event] Dispatched when the Flash Player or AIR application gains operating system focus and becomes active.EventDispatcher
 InheritedDispatched when a display object is added to the display list.DisplayObject
 InheritedDispatched 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
 InheritedDispatched when a display object is about to be removed from the display list.DisplayObject
 InheritedDispatched 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

deblocking

property
deblocking:int

Language Version: ActionScript 3.0
Runtime Versions: AIR 1.0 Flash Player 9, Flash Lite 4

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:

  • 0—Lets the video compressor apply the deblocking filter as needed.
  • 1—Does not use a deblocking filter.
  • 2—Uses the Sorenson deblocking filter.
  • 3—For On2 video only, uses the On2 deblocking filter but no deringing filter.
  • 4—For On2 video only, uses the On2 deblocking and deringing filter.
  • 5—For On2 video only, uses the On2 deblocking and a higher-performance On2 deringing filter.

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

smoothing

property 
smoothing:Boolean

Language Version: ActionScript 3.0
Runtime Versions: AIR 1.0 Flash Player 9, Flash Lite 4

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

videoHeight

property 
videoHeight:int  [read-only]

Language Version: ActionScript 3.0
Runtime Versions: AIR 1.0 Flash Player 9, Flash Lite 4

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 FLV files, this value is the height of the file that was exported as FLV.

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

videoWidth

property 
videoWidth:int  [read-only]

Language Version: ActionScript 3.0
Runtime Versions: AIR 1.0 Flash Player 9, Flash Lite 4

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 FLV files, this value is the width of the file that was exported as an FLV file.

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 Versions: AIR 1.0 Flash Player 9

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  ( How to use this 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 Versions: AIR 1.0 Flash Player 9

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.

Parameters

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

See also


Example
How to use this example
Please see the Camera.getCamera() method example for an illustration of how to use this method.

attachNetStream

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

Language Version: ActionScript 3.0
Runtime Versions: AIR 1.0 Flash Player 9, Flash Lite 4

Specifies a video stream to be displayed within the boundaries of the Video object in the application. The video stream is either an FLV file played with NetStream.play(), a Camera object, or null. If you use an FLV 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 the FLV file contains only audio; the audio portion of FLV files is played automatically when you call NetStream.play(). To control the audio associated with an FLV file, use the soundTransform property of the NetStream object that plays the FLV file.

Parameters

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

See also

clear

()method 
public function clear():void

Language Version: ActionScript 3.0
Runtime Versions: AIR 1.0 Flash Player 9, Flash Lite 4

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

VideoExample.as

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