Camera.setMode()

Availability

Usage

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

Parameters

width The requested capture width, in pixels. The default value is 160.

height The requested capture height, in pixels. The default value is 120.

fps The requested rate at which the camera should capture data, in frames per second. The default value is 15.

favorArea An optional 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.

Returns

Nothing.

Description

Method; 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.

If you are using Flash Media Server, you can also capture single frames or create time-lapsed photography. For more information, see NetStream.attachVideo().

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

See also

Camera.currentFps, Camera.fps, Camera.height, Camera.width, NetStream.attachVideo()


 

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

Current page: http://livedocs.adobe.com/fms/2/docs/00000546.html