Flash Media Server Developer Documentation

Video.attachVideo()

public attachVideo(source:Object) : Void

Specifies a video stream to be displayed within the boundaries of the Video object on the Stage. The video stream is either a NetStream object being displayed by means of the NetStream.play() command, a Camera object, or null. If source is null, video is no longer played within the Video object.

If the file contains only audio, you don't have to use this method. The audio portion of a file is played automatically when the NetStream.play() command is issued.

To control the audio, you can use MovieClip.attachAudio() to route the audio to a movie clip; you can then create a Sound object to control some aspects of the audio. For more information, see MovieClip.attachAudio().

Availability

Flash Communication Server 1; Flash Player 6.

Parameters

source A NetStream or Camera object that is playing video or audio data or capturing video data, respectively. To drop the connection to the Video object, pass null for source.

Example

The following example plays live video locally, without the need for Flash Media Server:

var active_cam:Camera = Camera.get();
my_video.attachVideo(active_cam); // my_video is a Video object on the Stage.

The following example shows how to publish and record a video and then play it back.

/* This script publishes and records video.
The recorded file will be named "allAboutMe". */
var my_nc:NetConnection = new NetConnection();
my_nc.connect("rtmp://localhost/allAboutMe/mySpeech");
var publish_ns:NetStream = new NetStream(my_nc);
publish_ns.publish("allAboutMe", "record");
publish_ns.attachVideo(Camera.get());

/* This script plays the recorded file.
Note that no publishing stream is required to play a recorded file. */
var my_nc:NetConnection = new NetConnection();
my_nc.connect("rtmp://localhost/allAboutMe/mySpeech");
var subscribe_ns:NetStream = new NetStream(my_nc);
subscribe_ns.play("allAboutMe");
my_video.attachVideo(subscribe_ns);    // my_video is a Video object on the Stage.

See also

Camera class, NetStream.play(), NetStream.publish()