flash.media

# Video - AS3

Package | flash.media
Class | public class Video
Inheritance | Video DisplayObject EventDispatcher Object
Subclasses | VideoPlayer

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

Learn more

Display programming
Basics of display programming
Core display classes
Taking advantage of mipmapping
Basics of video
Understanding video formats
Flash Player and AIR compatibility with encoded video files
Understanding the Adobe F4V and FLV video file formats
Understanding the Video class
Advanced topics for video files
Video example: Video Jukebox
Working with Video

Related API Elements

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

Public Properties
Hide Inherited Public Properties
Show Inherited Public Properties

| Property | Defined By
--- | --- | ---
|  | accessibilityProperties : AccessibilityProperties The current accessibility options for this display object. | DisplayObject
|  | alpha : Number Indicates the alpha transparency value of the object specified. | DisplayObject
|  | blendMode : String A value from the BlendMode class that specifies which blend mode to use. | DisplayObject
|  | blendShader : Shader [write-only] Sets a shader that is used for blending the foreground and background. | DisplayObject
|  | cacheAsBitmap : Boolean If set to true, Flash runtimes cache an internal bitmap representation of the display object. | DisplayObject
|  | cacheAsBitmapMatrix : Matrix If non-null, this Matrix object defines how a display object is rendered when cacheAsBitmap is set to true. | DisplayObject
|  | constructor : 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
|  | filters : Array An indexed array that contains each filter object currently associated with the display object. | DisplayObject
|  | height : Number Indicates the height of the display object, in pixels. | DisplayObject
|  | loaderInfo : LoaderInfo [read-only] Returns a LoaderInfo object containing information about loading the file to which this display object belongs. | DisplayObject
|  | mask : DisplayObject The calling display object is masked by the specified mask object. | DisplayObject
|  | metaData : 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
|  | mouseX : Number [read-only] Indicates the x coordinate of the mouse or user input device position, in pixels. | DisplayObject
|  | mouseY : Number [read-only] Indicates the y coordinate of the mouse or user input device position, in pixels. | DisplayObject
|  | name : String Indicates the instance name of the DisplayObject. | DisplayObject
|  | opaqueBackground : Object Specifies whether the display object is opaque with a certain background color. | DisplayObject
|  | parent : DisplayObjectContainer [read-only] Indicates the DisplayObjectContainer object that contains this display object. | DisplayObject
|  | root : 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
|  | rotation : Number Indicates the rotation of the DisplayObject instance, in degrees, from its original orientation. | DisplayObject
|  | rotationX : Number Indicates the x-axis rotation of the DisplayObject instance, in degrees, from its original orientation relative to the 3D parent container. | DisplayObject
|  | rotationY : Number Indicates the y-axis rotation of the DisplayObject instance, in degrees, from its original orientation relative to the 3D parent container. | DisplayObject
|  | rotationZ : Number Indicates the z-axis rotation of the DisplayObject instance, in degrees, from its original orientation relative to the 3D parent container. | DisplayObject
|  | scale9Grid : Rectangle The current scaling grid that is in effect. | DisplayObject
|  | scaleX : Number Indicates the horizontal scale (percentage) of the object as applied from the registration point. | DisplayObject
|  | scaleY : Number Indicates the vertical scale (percentage) of an object as applied from the registration point of the object. | DisplayObject
|  | scaleZ : Number Indicates the depth scale (percentage) of an object as applied from the registration point of the object. | DisplayObject
|  | scrollRect : 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
|  | stage : Stage [read-only] The Stage of the display object. | DisplayObject
|  | transform : 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
|  | visible : Boolean Whether or not the display object is visible. | DisplayObject
|  | width : Number Indicates the width of the display object, in pixels. | DisplayObject
|  | x : Number Indicates the x coordinate of the DisplayObject instance relative to the local coordinates of the parent DisplayObjectContainer. | DisplayObject
|  | y : Number Indicates the y coordinate of the DisplayObject instance relative to the local coordinates of the parent DisplayObjectContainer. | DisplayObject
|  | z : Number Indicates the z coordinate position along the z-axis of the DisplayObject instance relative to the 3D parent container. | DisplayObject

Public Methods
Hide Inherited Public Methods
Show Inherited Public Methods

| Method | Defined By
--- | --- | ---
|  | Video(width:int = 320, height:int = 240) Creates a new Video instance. | Video
|  | 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
|  | attachCamera(camera:Camera):void Specifies a video stream from a camera to be displayed within the boundaries of the Video object in the application. | Video
|  | attachNetStream(netStream:NetStream):void Specifies a video stream to be displayed within the boundaries of the Video object in the application. | Video
|  | clear():void Clears the image currently displayed in the Video object (not the video stream). | Video
|  | dispatchEvent(event:Event):Boolean Dispatches an event into the event flow. | EventDispatcher
|  | 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
|  | 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
|  | globalToLocal(point:Point):Point Converts the point object from the Stage (global) coordinates to the display object's (local) coordinates. | DisplayObject
|  | globalToLocal3D(point:Point):Vector3D Converts a two-dimensional point from the Stage (global) coordinates to a three-dimensional display object's (local) coordinates. | DisplayObject
|  | hasEventListener(type:String):Boolean Checks whether the EventDispatcher object has any listeners registered for a specific type of event. | EventDispatcher
|  | hasOwnProperty(name:String):Boolean Indicates whether an object has a specified property defined. | Object
|  | hitTestObject(obj:DisplayObject):Boolean 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
|  | 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
|  | isPrototypeOf(theClass:Object):Boolean Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter. | Object
|  | local3DToGlobal(point3d:Vector3D):Point 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
|  | localToGlobal(point:Point):Point Converts the point object from the display object's (local) coordinates to the Stage (global) coordinates. | DisplayObject
|  | propertyIsEnumerable(name:String):Boolean Indicates whether the specified property exists and is enumerable. | Object
|  | removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void Removes a listener from the EventDispatcher object. | EventDispatcher
|  | setPropertyIsEnumerable(name:String, isEnum:Boolean = true):void Sets the availability of a dynamic property for loop operations. | Object
|  | toLocaleString():String Returns the string representation of this object, formatted according to locale-specific conventions. | Object
|  | toString():String Returns the string representation of the specified object. | Object
|  | valueOf():Object Returns the primitive value of the specified object. | Object
|  | willTrigger(type:String):Boolean Checks whether an event listener is registered with this EventDispatcher object or any of its ancestors for the specified event type. | EventDispatcher

Events
Click for more information on events
Hide Inherited Events
Show Inherited Events

| Event | Summary | Defined By
--- | --- | --- | ---
|  | activate | [broadcast event] Dispatched when the Flash Player or AIR application gains operating system focus and becomes active. | EventDispatcher
|  | added | Dispatched when a display object is added to the display list. | DisplayObject
|  | addedToStage | 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
|  | deactivate | [broadcast event] Dispatched when the Flash Player or AIR application operating loses system focus and is becoming inactive. | EventDispatcher
|  | enterFrame | [broadcast event] Dispatched when the playhead is entering a new frame. | DisplayObject
|  | exitFrame | [broadcast event] Dispatched when the playhead is exiting the current frame. | DisplayObject
|  | frameConstructed | [broadcast event] Dispatched after the constructors of frame display objects have run but before frame scripts have run. | DisplayObject
|  | removed | Dispatched when a display object is about to be removed from the display list. | DisplayObject
|  | removedFromStage | 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
|  | render | [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`

Learn more

Taking advantage of mipmapping

### 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 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`

Related API Elements

flash.media.Camera.height

### 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 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`

Related API Elements

flash.media.Camera.width
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:
Copy

    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.

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

Related API Elements

Video.attachNetStream()
flash.media.Camera
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 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`.

Related API Elements

Video.attachCamera()
flash.net.NetStream.soundTransform
flash.net.NetStream.play()
SoundTransform

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

Related API Elements

Video.attachCamera()
Examples How to use this example
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()`.

Copy

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

© 2015 Adobe Systems Incorporated. All rights reserved.
Mon Apr 10 2017, 12:28 PM -07:00