ActionScript 3.0 Language and Components Reference | All Packages | All Classes | Language Elements | Index | Appendixes | Conventions | Frames No Frames |
Video

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

Language Version : | ActionScript 3.0

Player Version : | Flash Player 9

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 in an Adobe Flash or Adobe Flex interface that plays either of the following kinds of video: recorded Flash Video (FLV) files stored on a server or locally, or live video captured from a user's computer. 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 from a user's computer 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 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 versions support 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 the Flash authoring tool, 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

attachCamera()
attachNetStream()
flash.media.Camera.getCamera()
flash.net.NetConnection
flash.net.NetStream
flash.display.DisplayObjectContainer.addChild()
flash.display.Stage.addChild()
Core display classes
Basics of video

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
|  | cacheAsBitmap : Boolean If set to true, Flash Player caches an internal bitmap representation of the display object. | 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
|  | mouseX : Number [read-only] Indicates the x coordinate of the mouse position, in pixels. | DisplayObject
|  | mouseY : Number [read-only] Indicates the y coordinate of the mouse 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
|  | prototype : Object [static] A reference to the prototype object of a class or function object. | Object
|  | 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
|  | 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
|  | 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 : 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

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. | 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
|  | 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 display object to see if it overlaps or intersects with 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
|  | 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
|  | 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
Hide Inherited Events
Show Inherited Events

| Event | Summary | Defined By
--- | --- | --- | ---
|  | activate | Dispatched when Flash Player 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 | Dispatched when Flash Player loses operating system focus and is becoming inactive. | EventDispatcher
|  | enterFrame | Dispatched when the playhead is entering a new frame. | DisplayObject
|  | exitFrame | Dispatched when the playhead is exiting the current frame. | DisplayObject
|  | frameConstructed | 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 | Dispatched when the display list is about to be updated and rendered. | DisplayObject

Property Detail

deblocking | property

`deblocking:int` [read-write]

Language Version : | ActionScript 3.0

Player Version : | Flash Player 9

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` [read-write]

Language Version : | ActionScript 3.0

Player Version : | Flash Player 9

Specifies whether the video should be smoothed (interpolated) when it is scaled. For smoothing to work, the player must be in high-quality mode. 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

Player Version : | Flash Player 9

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

flash.media.Camera.height

videoWidth | property |

`videoWidth:int` [read-only]

Language Version : | ActionScript 3.0

Player Version : | Flash Player 9

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

flash.media.Camera.width
Constructor Detail

Video | () | Constructor

`public function Video(width:int = 320, height:int = 240)`

Language Version : | ActionScript 3.0

Player Version : | 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.

Method Detail

attachCamera | () | method

`public function attachCamera(camera:Camera):void`

Language Version : | ActionScript 3.0

Player Version : | 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 from a user's computer to the Video object. You can play the live video locally on the same computer 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

Video.attachNetStream()
flash.media.Camera
Example
How to use examples
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

Player Version : | Flash Player 9

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

Video.attachCamera()
flash.net.NetStream.soundTransform
flash.net.NetStream.play()
SoundTransform
Example
How to use examples
Please see the example at the end of this class for an illustration of how to use this method.

clear | () | method |

`public function clear():void`

Language Version : | ActionScript 3.0

Player Version : | Flash Player 9

Clears the image currently displayed in the Video object. This is useful when you want to display standby information without having to hide the Video object.

See also

Video.attachCamera()
Examples How to use examples
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.
            }
        }
     }

Submit Feedback on LiveDocs
© 2004-2008 Adobe Systems Incorporated. All rights reserved.
Tue May 20 2008, 04:02 AM -07:00