PackageTop Level
Classpublic class Camera
InheritanceCamera Inheritance Object

Player version: Flash Player 6

The Camera class is primarily for use with Flash Media Server, but can be used in a limited way without the server.

The Camera class lets you capture video from a video camera attached to the computer that is running Flash Player—for example, to monitor a video feed from a web camera attached to your local system. (Flash provides similar audio capabilities; for more information, see the Microphone class entry.)

Warning: When a SWF file tries to access the camera returned by Camera.get(), Flash Player displays a Privacy dialog box that lets the user choose whether to allow or deny access to the camera. (Make sure your Stage size is at least 215 x 138 pixels for the Camera class examples; this is the minimum size Flash requires to display the dialog box.) End users and administrative users may also disable camera access on a per-site or global basis.

To create or reference a Camera object, use the Camera.get() method.



Public Properties
 Property
  activityLevel : Number
[read-only]A numeric value that specifies the amount of motion the camera is detecting.
  bandwidth : Number
[read-only]An integer that specifies the maximum amount of bandwidth the current outgoing video feed can use, in bytes.
  currentFps : Number
[read-only]The rate at which the camera is capturing data, in frames per second.
  fps : Number
[read-only]The maximum rate at which you want the camera to capture data, in frames per second.
  height : Number
[read-only]The current capture height, in pixels.
  index : Number
[read-only]A zero-based integer that specifies the index of the camera, as reflected in the array returned by Camera.names.
  keyFrameInterval : Number
[read-only]A number that specifies which video frames are transmitted in full (called keyframes) instead of being interpolated by the video compression algorithm.
  loopback : Boolean
[read-only]A Boolean value that specifies whether a local view of what the camera is capturing is compressed (true) or uncompressed (false).
  motionLevel : Number
[read-only]A numeric value that specifies the amount of motion required to invoke Camera.onActivity(true).
  motionTimeOut : Number
[read-only]The number of milliseconds between the time the camera stops detecting motion and the time Camera.onActivity (false) is invoked.
  muted : Boolean
[read-only]A Boolean value that specifies whether the user has denied access to the camera (true) or allowed access (false) in the Flash Player Privacy Settings panel.
  name : String
[read-only]A string that specifies the name of the current camera, as returned by the camera hardware.
  names : Array
[static][read-only]Retrieves an array of strings reflecting the names of all available cameras without displaying the Flash Player Privacy Settings panel.
  quality : Number
[read-only]An integer specifying the required level of picture quality, as determined by the amount of compression being applied to each video frame.
  width : Number
[read-only]The current capture width, in pixels.
 Properties inherited from class Object
 __proto__, __resolve, constructor, prototype
Public Methods
 Method
  
get([index:Number]):Camera
[static]Returns a reference to a Camera object for capturing video.
  
setKeyFrameInterval(keyFrameInterval:Number):Void
Specifies which video frames are transmitted in full (called keyframes) instead of being interpolated by the video compression algorithm.
  
setLoopback(compress:Boolean):Void
Set to true to use a compressed video stream for a local view of what the camera is transmitting.
  
setMode([width:Number], [height:Number], [fps:Number], [favorArea:Boolean]):Void
Sets the camera capture mode to the native mode that best meets the specified requirements.
  
setMotionLevel([motionLevel:Number], [timeOut:Number]):Void
Specifies how much motion is required to invoke Camera.onActivity(true).
  
setQuality([bandwidth:Number], [quality:Number]):Void
Sets the maximum amount of bandwidth per second or the required picture quality of the current outgoing video feed.
 Methods inherited from class Object
 addProperty, hasOwnProperty, isPropertyEnumerable, isPrototypeOf, registerClass, toString, unwatch, valueOf, watch
Events
 EventSummaryDefined by
  
onActivity = function(active:Boolean) {}
Invoked when the camera starts or stops detecting motion.Camera
  
onStatus = function(infoObject:Object) {}
Invoked when the user allows or denies access to the camera.Camera
Property detail
activityLevelproperty
activityLevel:Number  [read-only]

Player version: Flash Player 6

A numeric value that specifies the amount of motion the camera is detecting. Values range from 0 (no motion is being detected) to 100 (a large amount of motion is being detected). The value of this property can help you determine if you need to pass a setting to Camera.setMotionLevel().

If the camera is available but is not yet being used because Video.attachVideo() has not been called, this property is set to -1.

If you are streaming only uncompressed local video, this property is set only if you have assigned a function to the Camera.onActivity event handler. Otherwise, it is undefined.

Implementation
    public function get activityLevel():Number

See also


Example
The following example detects the amount of motion the camera detects using the activityLevel property: This example detects the amount of motion the camera detects using the activityLevel property and a ProgressBar instance. Create a new video instance by selecting New Video from the Library options menu. Add an instance to the Stage and give it the instance name my_video. Add a ProgressBar component instance to the Stage and give it the instance name activity_pb. Then add the following ActionScript to Frame 1 of the Timeline:
// video instance on the Stage.
var my_video:Video;
var activity_pb:mx.controls.ProgressBar;
var my_cam:Camera = Camera.get();
my_video.attachVideo(my_cam);
activity_pb.mode = "manual";
activity_pb.label = "Activity %3%%";

this.onEnterFrame = function() {
    activity_pb.setProgress(my_cam.activityLevel, 100);
};
my_cam.onActivity = function(isActive:Boolean) {
    var themeColor:String = (isActive) ? "haloGreen" : "haloOrange";
    activity_pb.setStyle("themeColor", themeColor);
};

bandwidthproperty 
bandwidth:Number  [read-only]

Player version: Flash Player 6

An integer that specifies the maximum amount of bandwidth the current outgoing video feed can use, in bytes. A value of 0 means that Flash video can use as much bandwidth as needed to maintain the desired frame quality.

To set this property, use Camera.setQuality().

Implementation
    public function get bandwidth():Number

See also


Example
The following example changes the maximum amount of bandwidth used by the camera feed. Create a new video instance by selecting New Video from the Library options menu. Add an instance to the Stage and give it the instance name my_video. Add a NumericStepper component instance to the Stage and give it the instance name bandwidth_nstep. Then add the following ActionScript to Frame 1 of the Timeline:
var bandwidth_nstep:mx.controls.NumericStepper;
var my_video:Video;
var my_cam:Camera = Camera.get();
my_video.attachVideo(my_cam);
this.createTextField("bandwidth_txt", this.getNextHighestDepth(), 0, 0, 100, 22);
bandwidth_txt.autoSize = true;
this.onEnterFrame = function() {
    bandwidth_txt.text = "Camera is currently using "+my_cam.bandwidth+" bytes ("+Math.round(my_cam.bandwidth/1024)+" KB) bandwidth.";
};
//
bandwidth_nstep.minimum = 0;
bandwidth_nstep.maximum = 128;
bandwidth_nstep.stepSize = 16;
bandwidth_nstep.value = my_cam.bandwidth/1024;
function changeBandwidth(evt:Object) {
    my_cam.setQuality(evt.target.value 1024, 0);
}
bandwidth_nstep.addEventListener("change", changeBandwidth);

The MovieClip.getNextHighestDepth() method used in this example requires Flash Player 7 or later. If your SWF file includes a version 2 component, use the version 2 components' DepthManager class instead of the MovieClip.getNextHighestDepth() method.

currentFpsproperty 
currentFps:Number  [read-only]

Player version: Flash Player 6

The rate at which the camera is capturing data, in frames per second. This property cannot be set; however, you can use the Camera.setMode() method to set a related property--Camera.fps--which specifies the maximum frame rate at which you would like the camera to capture data.

Implementation
    public function get currentFps():Number

See also


Example
The following example detects the rate in frames per second that the camera captures data, using the currentFps property: The following example detects the rate in frames per second that the camera captures data, using the currentFps property and a ProgressBar instance. Create a new video instance by selecting New Video from the Library options menu. Add an instance to the Stage and give it the instance name my_video. Add a ProgressBar component instance to the Stage and give it the instance name fps_pb. Then add the following ActionScript to Frame 1 of the Timeline:
var my_video:Video;
var fps_pb:mx.controls.ProgressBar;
var my_cam:Camera = Camera.get();
my_video.attachVideo(my_cam);
this.onEnterFrame = function() {
    fps_pb.setProgress(my_cam.fps-my_cam.currentFps, my_cam.fps);
};

fps_pb.setStyle("fontSize", 10);
fps_pb.setStyle("themeColor", "haloOrange");
fps_pb.labelPlacement = "top";
fps_pb.mode = "manual";
fps_pb.label = "FPS: %2 (%3%% dropped)";

fpsproperty 
fps:Number  [read-only]

Player version: Flash Player 6

The maximum rate at which you want the camera to capture data, in frames per second. The maximum rate possible depends on the capabilities of the camera; that is, if the camera doesn't support the value you set here, this frame rate will not be achieved.

Implementation
    public function get fps():Number

See also


Example
The following example detects the rate in frames per second that the camera captures data, using the currentFps property: The following example detects the rate in frames per second that the camera captures data, using the currentFps property and a ProgressBar instance. Create a new video instance by selecting New Video from the Library options menu. Add an instance to the Stage and give it the instance name my_video. Add a ProgressBar component instance to the Stage and give it the instance name fps_pb. Then add the following ActionScript to Frame 1 of the Timeline:
var my_video:Video;
var fps_pb:mx.controls.ProgressBar;
var my_cam:Camera = Camera.get();
my_video.attachVideo(my_cam);
this.onEnterFrame = function() {
    fps_pb.setProgress(my_cam.fps-my_cam.currentFps, my_cam.fps);
};

fps_pb.setStyle("fontSize", 10);
fps_pb.setStyle("themeColor", "haloOrange");
fps_pb.labelPlacement = "top";
fps_pb.mode = "manual";
fps_pb.label = "FPS: %2 (%3%% dropped)";

Note: The setMode() function does not guarantee the requested fps setting; it sets the fps you requested or the fastest fps available.

heightproperty 
height:Number  [read-only]

Player version: Flash Player 6

The current capture height, in pixels. To set a value for this property, use Camera.setMode().

Implementation
    public function get height():Number

See also


Example
The following code displays the current width, height and FPS of a video instance in a Label component instance on the Stage. Create a new video instance by selecting New Video from the Library options menu. Add an instance to the Stage and give it the instance name my_video. Add a Label component instance to the Stage and give it the instance name dimensions_lbl. Then add the following ActionScript to Frame 1 of the Timeline:
var my_cam:Camera = Camera.get();
var my_video:Video;
my_video.attachVideo(my_cam);
var dimensions_lbl:mx.controls.Label;
dimensions_lbl.setStyle("fontSize", 9);
dimensions_lbl.setStyle("fontWeight", "bold");
dimensions_lbl.setStyle("textAlign", "center");
dimensions_lbl.text = "width: "+my_cam.width+", height: "+my_cam.height+", FPS: "+my_cam.fps;

See also the example for Camera.setMode().

indexproperty 
index:Number  [read-only]

Player version: Flash Player 6

A zero-based integer that specifies the index of the camera, as reflected in the array returned by Camera.names.

Implementation
    public function get index():Number

See also


Example
The following example displays an array of cameras in a text field that is created at runtime, and tells you which camera you are currently using. Create a new video instance by selecting New Video from the Library options menu. Add an instance to the Stage and give it the instance name my_video. Add a Label component instance to the Stage and give it the instance name camera_lbl. Then add the following ActionScript to Frame 1 of the Timeline:
var camera_lbl:mx.controls.Label;
var my_cam:Camera = Camera.get();
var my_video:Video;
my_video.attachVideo(my_cam);

camera_lbl.text = my_cam.index+". "+my_cam.name;
this.createTextField("cameras_txt", this.getNextHighestDepth(), 25, 160, 160, 80);
cameras_txt.html = true;
cameras_txt.border = true;
cameras_txt.wordWrap = true;
cameras_txt.multiline = true;
for (var i = 0; i<Camera.names.length; i++) {
    cameras_txt.htmlText += "<li><u><a href=\"asfunction:changeCamera,"+i+"\">"+Camera.names[i]+"</a></u></li>";
}
function changeCamera(index:Number) {
    my_cam = Camera.get(index);
    my_video.attachVideo(my_cam);
    camera_lbl.text = my_cam.index+". "+my_cam.name;
}

The MovieClip.getNextHighestDepth() method used in this example requires Flash Player 7 or later. If your SWF file includes a version 2 component, use the version 2 components' DepthManager class instead of the MovieClip.getNextHighestDepth() method.

keyFrameIntervalproperty 
keyFrameInterval:Number  [read-only]

Language version: ActionScript 2.0
Player version: Flash Player 6

A number that specifies which video frames are transmitted in full (called keyframes) instead of being interpolated by the video compression algorithm. The default value is 15, which means every 15th frame is a keyframe. A value of 1 means that every frame is a keyframe. The allowed values are 1 through 48.

Implementation
    public function get keyFrameInterval():Number

See also

loopbackproperty 
loopback:Boolean  [read-only]

Language version: ActionScript 2.0
Player version: Flash Player 6

A Boolean value that specifies whether a local view of what the camera is capturing is compressed (true) or uncompressed (false). The loopback is normally true for live transmission using Flash Media Server. The default value is false.

To set this value, use Camera.setLoopback(). To set the amount of compression used when this property is true, use Camera.setQuality().

Implementation
    public function get loopback():Boolean

See also

motionLevelproperty 
motionLevel:Number  [read-only]

Player version: Flash Player 6

A numeric value that specifies the amount of motion required to invoke Camera.onActivity(true). Acceptable values range from 0 to 100. The default value is 50.

Video can be displayed regardless of the value of the motionLevel property. For more information, see Camera.setMotionLevel().

Implementation
    public function get motionLevel():Number

See also


Example
The following example continually detects the motion level of a camera feed. Create a new video instance by selecting New Video from the Library options menu. Add an instance to the Stage and give it the instance name my_video. Add a Label component instance to the Stage and give it the instance name motionLevel_lbl, a NumericStepper with the instance name motionLevel_nstep, and a ProgressBar with the instance name motion_pb. Then add the following ActionScript to Frame 1 of the Timeline:
var my_cam:Camera = Camera.get();
var my_video:Video;
my_video.attachVideo(my_cam);

// configure the ProgressBar component instance
var motion_pb:mx.controls.ProgressBar;
motion_pb.mode = "manual";
motion_pb.label = "Motion: %3%%";

var motionLevel_lbl:mx.controls.Label;
// configure the NumericStepper component instance
var motionLevel_nstep:mx.controls.NumericStepper;
motionLevel_nstep.minimum = 0;
motionLevel_nstep.maximum = 100;
motionLevel_nstep.stepSize = 5;
motionLevel_nstep.value = my_cam.motionLevel;

// Continuously update the progress of the ProgressBar component instance to the activityLevel 
// of the current Camera instance, which is defined in my_cam 
this.onEnterFrame = function() {
    motion_pb.setProgress(my_cam.activityLevel, 100);
};

// When the level of activity goes above or below the number defined in Camera.motionLevel, 
// trigger the onActivity event handler. 
my_cam.onActivity = function(isActive:Boolean) {
    // If isActive equals true, set the themeColor variable to "haloGreen". 
    // Otherwise set the themeColor to "haloOrange". 
    var themeColor:String = (isActive) ? "haloGreen" : "haloOrange";
    motion_pb.setStyle("themeColor", themeColor);
};

function changeMotionLevel() {
    // Set the motionLevel property for my_cam Camera instance to the value of the NumericStepper 
    // component instance. Maintain the current motionTimeOut value of the my_cam Camera instance. 
    my_cam.setMotionLevel(motionLevel_nstep.value, my_cam.motionTimeOut);
}
motionLevel_nstep.addEventListener("change", changeMotionLevel);

motionTimeOutproperty 
motionTimeOut:Number  [read-only]

Player version: Flash Player 6

The number of milliseconds between the time the camera stops detecting motion and the time Camera.onActivity (false) is invoked. The default value is 2000 (2 seconds).

To set this value, use Camera.setMotionLevel().

Implementation
    public function get motionTimeOut():Number

See also


Example
In the following example, the ProgressBar instance changes its halo theme color when the activity level falls below the motion level. You can set the number of seconds for the motionTimeOut property using a NumericStepper instance. Create a new video instance by selecting New Video from the Library options menu. Add an instance to the Stage and give it the instance name my_video. Add a Label component instance to the Stage and give it the instance name motionLevel_lbl, a NumericStepper with the instance name motionTimeOut_nstep, and a ProgressBar with the instance name motion_pb. Then add the following ActionScript to Frame 1 of the Timeline:
var motionLevel_lbl:mx.controls.Label;
var motion_pb:mx.controls.ProgressBar;
var motionTimeOut_nstep:mx.controls.NumericStepper;
var my_cam:Camera = Camera.get();
var my_video:Video;
my_video.attachVideo(my_cam);

this.onEnterFrame = function() {
    motionLevel_lbl.text = "activityLevel: "+my_cam.activityLevel;
};

motion_pb.indeterminate = true;
my_cam.onActivity = function(isActive:Boolean) {
    if (isActive) {
    motion_pb.setStyle("themeColor", "haloGreen");
    motion_pb.label = "Motion is above "+my_cam.motionLevel;
    } else {
    motion_pb.setStyle("themeColor", "haloOrange");
    motion_pb.label = "Motion is below "+my_cam.motionLevel;
    }
};
function changeMotionTimeOut() {
    my_cam.setMotionLevel(my_cam.motionLevel, motionTimeOut_nstep.value 1000);
}
motionTimeOut_nstep.addEventListener("change", changeMotionTimeOut);
motionTimeOut_nstep.value = my_cam.motionTimeOut/1000;

mutedproperty 
muted:Boolean  [read-only]

Player version: Flash Player 6

A Boolean value that specifies whether the user has denied access to the camera (true) or allowed access (false) in the Flash Player Privacy Settings panel. When this value changes, Camera.onStatus is invoked. For more information, see Camera.get().

Implementation
    public function get muted():Boolean

See also


Example
In the following example, an error message could be displayed if my_cam.muted evaluates to true. Create a new video instance by selecting New Video from the Library options menu. Add an instance to the Stage and give it the instance name my_video. Then add the following ActionScript to Frame 1 of the Timeline:
var my_cam:Camera = Camera.get();
var my_video:Video;
my_video.attachVideo(my_cam);
my_cam.onStatus = function(infoObj:Object) {
    if (my_cam.muted) {
    // If user is denied access to their Camera, you can display an error message here. You can display the user's Camera/Privacy settings again using System.showSettings(0); 
    trace("User denied access to Camera");
    System.showSettings(0);
    }
};

nameproperty 
name:String  [read-only]

Player version: Flash Player 6

A string that specifies the name of the current camera, as returned by the camera hardware.

Implementation
    public function get name():String

See also


Example
The following example displays the name of the default camera in a text field. The following example writes the name of the default camera to the log file. In Windows, this name is the same as the device name listed in the Scanners and Cameras Control Panel. Create a new video instance by selecting New Video from the Library options menu. Add an instance to the Stage and give it the instance name my_video. Then add the following ActionScript to Frame 1 of the Timeline:
var my_cam:Camera = Camera.get();
var my_video:Video;
my_video.attachVideo(my_cam);

this.createTextField("name_txt", this.getNextHighestDepth(), 0, 0, 100, 22);
name_txt.autoSize = true;
name_txt.text = my_cam.name;

The MovieClip.getNextHighestDepth() method used in this example requires Flash Player 7 or later. If your SWF file includes a version 2 component, use the version 2 components' DepthManager class instead of the MovieClip.getNextHighestDepth() method.

namesproperty 
names:Array  [read-only]

Player version: Flash Player 6

Retrieves an array of strings reflecting the names of all available cameras without displaying the Flash Player Privacy Settings panel. This array behaves in the same way as any other ActionScript array, implicitly providing the zero-based index of each camera and the number of cameras on the system (by means of Camera.names.length). For more information, see the Camera.names Array class entry.

Calling the Camera.names property requires an extensive examination of the hardware, and it may take several seconds to build the array. In most cases, you can just use the default camera.

Note: The correct syntax is Camera.names. To assign the return value to a variable, use syntax like cam_array = Camera.names. To determine the name of the current camera, use active_cam.name.

Implementation
    public static function get names():Array

See also


Example
The following example uses the default camera unless more than one camera is available, in which case the user can choose which camera to set as the default camera. If only one camera is present, then the default camera is used. Create a new video instance by selecting New Video from the Library options menu. Add an instance to the Stage and give it the instance name my_video. Then add the following ActionScript to Frame 1 of the Timeline:
var my_video:Video;
var cam_array:Array = Camera.names;
if (cam_array.length>1) {
    System.showSettings(3);
}
var my_cam:Camera = Camera.get();
my_video.attachVideo(my_cam);

qualityproperty 
quality:Number  [read-only]

Player version: Flash Player 6

An integer specifying the required level of picture quality, as determined by the amount of compression being applied to each video frame. Acceptable quality values range from 1 (lowest quality, maximum compression) to 100 (highest quality, no compression). The default value is 0, which means that picture quality can vary as needed to avoid exceeding available bandwidth.

Implementation
    public function get quality():Number

See also


Example
The following example uses a NumericStepper instance to specify the amount of compression applied to the camera feed. Create a new video instance by selecting New Video from the Library options menu. Add an instance to the Stage and give it the instance name my_video. Add a NumericStepper with the instance name quality_nstep. Then add the following ActionScript to Frame 1 of the Timeline:
var quality_nstep:mx.controls.NumericStepper;

var my_cam:Camera = Camera.get();
var my_video:Video;
my_video.attachVideo(my_cam);

quality_nstep.minimum = 0;
quality_nstep.maximum = 100;
quality_nstep.stepSize = 5;
quality_nstep.value = my_cam.quality;

function changeQuality() {
    my_cam.setQuality(my_cam.bandwidth, quality_nstep.value);
}
quality_nstep.addEventListener("change", changeQuality);

widthproperty 
width:Number  [read-only]

Player version: Flash Player 6

The current capture width, in pixels. To set a desired value for this property, use Camera.setMode().

Implementation
    public function get width():Number

See also


Example
The following code displays the current width, height and FPS of a video instance in a Label component instance on the Stage. Create a new video instance by selecting New Video from the Library options menu. Add an instance to the Stage and give it the instance name my_video. Add a Label component instance to the Stage and give it the instance name dimensions_lbl. Then add the following ActionScript to Frame 1 of the Timeline:
var my_cam:Camera = Camera.get();
var my_video:Video;
my_video.attachVideo(my_cam);
var dimensions_lbl:mx.controls.Label;
dimensions_lbl.setStyle("fontSize", 9);
dimensions_lbl.setStyle("fontWeight", "bold");
dimensions_lbl.setStyle("textAlign", "center");
dimensions_lbl.text = "width: "+my_cam.width+", height: "+my_cam.height+", FPS: "+my_cam.fps;

See also the example for Camera.setMode().

Method detail
get()method
public static function get([index:Number]):Camera

Player version: Flash Player 6

Returns a reference to a Camera object for capturing video. To actually begin capturing the video, you must attach the Camera object to a Video object (see Video.attachVideo()).

Unlike objects that you create using the new constructor, multiple calls to Camera.get() reference the same camera. Thus, if your script contains the lines first_cam = Camera.get() and second_cam = Camera.get(), both first_cam and second_cam reference the same (default) camera.

In general, you shouldn't pass a value for index; simply use Camera.get() to return a reference to the default camera. By means of the Camera settings panel (discussed later in this section), the user can specify the default camera Flash should use. If you pass a value for index, you might be trying to reference a camera other than the one the user prefers. You might use index in rare cases--for example, if your application is capturing video from two cameras at the same time.

When a SWF file tries to access the camera returned by Camera.get(), Flash Player displays a Privacy dialog box that lets the user choose whether to allow or deny access to the camera. (Make sure your Stage size is at least 215 x 138 pixels; this is the minimum size Flash requires to display the dialog box.)

When the user responds to this dialog box, the Camera.onStatus event handler returns an information object that indicates the user's response. To determine whether the user has denied or allowed access to the camera without processing this event handler, use the Camera.muted property.

The user can also specify permanent privacy settings for a particular domain by right-clicking (Windows) or Control-clicking (Macintosh) while a SWF file is playing, selecting Settings, opening the Privacy panel, and selecting Remember.

You can't use ActionScript to set the Allow or Deny value for a user, but you can display the Privacy panel for the user by using System.showSettings(0). If the user selects Remember, Flash Player no longer displays the Privacy dialog box for SWF files from this domain.

If Camera.get returns null, either the camera is in use by another application, or there are no cameras installed on the system. To determine whether any cameras are installed, use Camera.names.length. To display the Flash Player Camera Settings panel, which lets the user choose the camera to be referenced by Camera.get(), use System.showSettings(3).

Scanning the hardware for cameras takes time. When Flash finds at least one camera, the hardware is not scanned again for the lifetime of the player instance. However, if Flash doesn't find any cameras, it will scan each time Camera.get is called. This is helpful if a user has forgotten to connect the camera; if your SWF file provides a Try Again button that calls Camera.get, Flash can find the camera without the user having to restart the SWF file.

Note: The correct syntax is Camera.get(). To assign the Camera object to a variable, use syntax like active_cam = Camera.get().

Parameters
index:Number [optional] — A zero-based integer that specifies which camera to get, as determined from the array returned by the Camera.names property. To get the default camera (which is recommended for most applications), omit this parameter.

Returns
Camera — If index is not specified, this method returns a reference to the default camera or, if it is in use by another application, to the first available camera. (If there is more than one camera installed, the user may specify the default camera in the Flash Player Camera Settings panel.) If no cameras are available or installed, the method returns null. If index is specified, this method returns a reference to the requested camera, or null if it is not available.

See also


Example
The following example lets you select an active camera to use from a ComboBox instance. The current active camera is displayed in a Label instance. Create a new video instance by selecting New Video from the Library options menu. Add an instance to the Stage and give it the instance name my_video. Add a Label component instance to the Stage and give it the instance name camera_lbl, and a ComboBox component instance and give it the instance name cameras_cb. Then add the following ActionScript to Frame 1 of the Timeline:
var my_cam:Camera = Camera.get();
var my_video:Video;
my_video.attachVideo(my_cam);
var camera_lbl:mx.controls.Label;
var cameras_cb:mx.controls.ComboBox;
camera_lbl.text = my_cam.name;
cameras_cb.dataProvider = Camera.names;
function changeCamera():Void {
    my_cam = Camera.get(cameras_cb.selectedIndex);
    my_video.attachVideo(my_cam);
    camera_lbl.text = my_cam.name;
}
cameras_cb.addEventListener("change", changeCamera);
camera_lbl.setStyle("fontSize", 9);
cameras_cb.setStyle("fontSize", 9);

setKeyFrameInterval()method 
public function setKeyFrameInterval(keyFrameInterval:Number):Void

Language version: ActionScript 2.0
Player version: Flash Player 6

Specifies which video frames are transmitted in full (called keyframes) instead of being interpolated by the video compression algorithm. This method is generally applicable only if you are transmitting video using Flash Media Server.

For more information, see the Flash Media Server documentation.

Parameters
keyFrameInterval:Number — A number specifying which video frames are transmitted in full (called keyframes) The default is 15.

See also

setLoopback()method 
public function setLoopback(compress:Boolean):Void

Language version: ActionScript 2.0
Player version: Flash Player 6

Set to true to use a compressed video stream for a local view of what the camera is transmitting. The default is false. This method is generally applicable only if you are transmitting video using Flash Media Server.

To set the amount of compression used when you set compress to true, use Camera.setQuality().

Parameters
compress:Boolean — A boolean value that is true to use a compressed stream or false to use an uncompressed stream of the view the camera is receiving.

See also

setMode()method 
public function setMode([width:Number], [height:Number], [fps:Number], [favorArea:Boolean]):Void

Player version: Flash Player 6

Sets the camera capture mode to the native mode that best meets the specified requirements. If the camera does not have a native mode that matches all the parameters you pass, Flash selects a capture mode that most closely synthesizes the requested mode. This manipulation may involve cropping the image and dropping frames.

By default, Flash drops frames as needed to maintain image size. To minimize the number of dropped frames, even if this means reducing the size of the image, pass false for the favorArea parameter.

When choosing a native mode, Flash tries to maintain the requested aspect ratio whenever possible. For example, if you issue the command active_cam.setMode(400, 400, 30), and the maximum width and height values available on the camera are 320 and 288, Flash sets both the width and height at 288; by setting these properties to the same value, Flash maintains the 1:1 aspect ratio you requested.

To determine the values assigned to these properties after Flash selects the mode that most closely matches your requested values, use Camera.width, Camera.height, and Camera.fps.

Parameters
width:Number [optional] — The requested capture width, in pixels. The default value is 160.
 
height:Number [optional] — The requested capture height, in pixels. The default value is 120.
 
fps:Number [optional] — The requested rate at which the camera should capture data, in frames per second. The default value is 15.
 
favorArea:Boolean [optional] — A Boolean value that specifies how to manipulate the width, height, and frame rate if the camera does not have a native mode that meets the specified requirements. The default value is true, which means that maintaining capture size is favored; using this parameter selects the mode that most closely matches width and height values, even if doing so adversely affects performance by reducing the frame rate. To maximize frame rate at the expense of camera height and width, pass false for the favorArea parameter.

See also


Example
The following example sets the camera capture mode. You can type a frame rate into a TextInput instance and press Enter or Return to apply the frame rate. Create a new video instance by selecting New Video from the Library options menu. Add an instance to the Stage and give it the instance name my_video. Add a TextInput component instance with the instance name fps_ti. Then add the following ActionScript to Frame 1 of the Timeline:
var my_cam:Camera = Camera.get();
var my_video:Video;
my_video.attachVideo(my_cam);

fps_ti.maxChars = 2;
fps_ti.restrict = [0-9];
fps_lbl.text = "Current: "+my_cam.fps+" fps";

function changeFps():Void {
    my_cam.setMode(my_cam.width, my_cam.height, fps_ti.text);
    fps_lbl.text = "Current: "+my_cam.fps+" fps";
    fps_ti.text = my_cam.fps;
    Selection.setSelection(0,2);
}
fps_ti.addEventListener("enter", changeFps);

setMotionLevel()method 
public function setMotionLevel([motionLevel:Number], [timeOut:Number]):Void

Player version: Flash Player 6

Specifies how much motion is required to invoke Camera.onActivity(true). Optionally sets the number of milliseconds that must elapse without activity before Flash considers motion to have stopped and invokes Camera.onActivity(false).

Note: Video can be displayed regardless of the value of the sensitivity parameter. This parameter determines only when and under what circumstances Camera.onActivity is invoked--not whether video is actually being captured or displayed.

Parameters
motionLevel:Number [optional] — A numeric value that specifies the amount of motion required to invoke Camera.onActivity(true). Acceptable values range from 0 to 100. The default value is 50.
 
timeOut:Number [optional] — A numeric parameter that specifies how many milliseconds must elapse without activity before Flash considers activity to have stopped and invokes the Camera.onActivity(false) event handler. The default value is 2000 (2 seconds).

See also


Example
The following example sends messages to the Output panel when video activity starts or stops. The following example writes to the log file when video activity starts or stops. Change the motion sensitivity value of 30 to a higher or lower number to see how different values affect motion detection.
// Assumes a Video object named "myVideoObject" is on the Stage
active_cam = Camera.get();
x = 0;
function motion(mode) {
    trace(x + ": " + mode);
    x++;
}
active_cam.onActivity = function(mode) {
    motion(mode);
}
active_cam.setMotionLevel(30, 500);
myVideoObject.attachVideo(active_cam);

setQuality()method 
public function setQuality([bandwidth:Number], [quality:Number]):Void

Player version: Flash Player 6

Sets the maximum amount of bandwidth per second or the required picture quality of the current outgoing video feed. This method is generally applicable only if you are transmitting video using Flash Media Server.

Use this method to specify which element of the outgoing video feed is more important to your application--bandwidth use or picture quality.

Parameters
bandwidth:Number [optional] — An integer that specifies the maximum amount of bandwidth that the current outgoing video feed can use, in bytes per second. To specify that Flash video can use as much bandwidth as needed to maintain the value of frameQuality, pass 0 for bandwidth. The default value is 16384.
 
quality:Number [optional] — An integer that specifies the required level of picture quality, as determined by the amount of compression being applied to each video frame. Acceptable values range from 1 (lowest quality, maximum compression) to 100 (highest quality, no compression). To specify that picture quality can vary as needed to avoid exceeding bandwidth, pass 0 for quality. The default value is 0.

See also


Example
The following examples illustrate how to use this method to control bandwidth use and picture quality.
// Ensure that no more than 8192 (8K/second) is used to send video
active_cam.setQuality(8192,0);

// Ensure that no more than 8192 (8K/second) is used to send video
// with a minimum quality of 50
active_cam.setQuality(8192,50);

// Ensure a minimum quality of 50, no matter how much bandwidth it takes
active_cam.setQuality(0,50);

Event detail
onActivityevent handler

public onActivity = function(active:Boolean) {}

Player version: Flash Player 6

Invoked when the camera starts or stops detecting motion. If you want to respond to this event handler, you must create a function to process its activity value.

To specify the amount of motion required to invoke Camera.onActivity(true) and the amount of time that must elapse without activity before invoking Camera.onActivity(false), use Camera.setMotionLevel().

Parameters
active:Boolean — A Boolean value set to true when the camera starts detecting motion, false when the motion stops.

Example
The following example displays true or false in the Output panel when the camera starts or stops detecting motion: The following example writes to the log file when the camera starts or stops detecting motion:
// Assumes a Video object named "myVideoObject" is on the Stage
active_cam = Camera.get();
myVideoObject.attachVideo(active_cam);
active_cam.setMotionLevel(10, 500);
active_cam.onActivity = function(mode)
{
    trace(mode);
}

See also

onStatusevent handler 

public onStatus = function(infoObject:Object) {}

Player version: Flash Player 6

Invoked when the user allows or denies access to the camera. If you want to respond to this event handler, you must create a function to process the information object generated by the camera.

When a SWF file tries to access the camera, Flash Player displays a Privacy dialog box that lets the user choose whether to allow or deny access.

To determine whether the user has denied or allowed access to the camera without processing this event handler, use the Camera.muted property.

Note: If the user chooses to permanently allow or deny access for all SWF files from a specified domain, this handler is not invoked for SWF files from that domain unless the user later changes the privacy setting. For more information, see Camera.get().

Parameters
infoObject:Object — A parameter defined according to the status message.

Example
The following ActionScript is used to display a message whenever the user allows or denies access to the camera: The following event handler writes the results of the trace() method to the log file:
var my_cam:Camera = Camera.get();
var my_video:Video;
my_video.attachVideo(my_cam);
my_cam.onStatus = function(infoObj:Object) {
    switch (infoObj.code) {
    case 'Camera.Muted' :
    trace("Camera access is denied");
    break;
    case 'Camera.Unmuted' :
    trace("Camera access granted");
    break;
    }
}

See also