View comments | RSS feed

Video.attachVideo()

Availability

Flash Player 6; the ability to work with Flash Video (FLV) files was added in Flash Player 7.

Usage

my_video.attachVideo(source:Object) : Void

Parameters

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

Returns

Nothing.

Description

Method; specifies a video stream (source) to be displayed within the boundaries of the Video object on the Stage. The video stream is either an FLV file 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.

You don't have to use this method if the FLV file contains only audio; the audio portion of an FLV files is played automatically when the NetStream.play() command is issued.

If you want to control the audio associated with an FLV file, 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().

Example

The following example plays live video locally:

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

The following example plays a previously recorded file named myVideo.flv that is stored in the same directory as the SWF file.

var my_video:Video; // my_video is a Video object on the Stage
var my_nc:NetConnection = new NetConnection();
my_nc.connect(null);
var my_ns:NetStream = new NetStream(my_nc);
my_video.attachVideo(my_ns);
my_ns.play("video1.flv");

See also

Camera class, NetStream class


Comments


_Maulik said on Jul 22, 2005 at 3:51 AM :
attaching null to the video object is not working ...
ali mills said on Jul 22, 2005 at 8:44 AM :
Huh, the example above works fine for me. _Maulik, are you having trouble with this example:

var my_video:Video; // my_video is a Video object on the Stage
var my_nc:NetConnection = new NetConnection();
my_nc.connect(null);
var my_ns:NetStream = new NetStream(my_nc);
my_video.attachVideo(my_ns);
my_ns.play(YOUR_FLV_URI);

Because, after copying and pasting it into the actions panel, it worked just fine for me. Maybe you're not actually dragging an Embedded Video object from the library to the stage? To do so, you should:

1. in the upper right corner of the Library, open the Library menu options (looks like a bulleted dropdown)
2. select "New Video"
3. drag the new video from the library to your stage
4. click the instance on stage and give it the instance name "my_video" in Properties
5. make sure the URI to your FLV is correct
6. test movie

The above steps work perfectly for me.
amjad-ghost said on Sep 1, 2005 at 3:08 AM :
I tried it,
i can only hear the audio but no image is displayed,
is there anything missing?
==============================
var my_video:Video; // my_video is a Video object on the Stage
var my_nc:NetConnection = new NetConnection();
my_nc.connect(null);
var my_ns:NetStream = new NetStream(my_nc);
my_video.attachVideo(my_ns);
my_ns.play("video1.flv");
===============================
John Whittington said on Mar 9, 2006 at 2:19 PM :
I was having the same problem. It turned out that while I was targeting the MediaDisplay component (Flash 6&7), my FLV was being encoded using the On2 VP6 codec. This still worked for viewers who had Flash Player 8, but viewers with 6 or 7 got audio without video.
Using the Sorenson Spark codec to encode the FLV worked for all viewers with Flash 6+. No AS code changes were necessary.
jdehaan said on Mar 10, 2006 at 10:33 AM :
Good tip, thanks! Just a quick note that this is something to watch for when you're using Flash 8 as opposed to Flash MX 2004.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/mx2004/main_7_2/00001873.html