MACROMEDIA MEDIA SERVER 2 Reference

Client-Side ActionScript Language Reference for Flash Media Server 2
Trademarks
1 Step RoboPDF, ActiveEdit, ActiveTest, Authorware, Blue Sky Software, Blue Sky, Breeze, Breezo, Captivate, Central, ColdFusion, Contribute, Database Explorer, Director, Dreamweaver, Fireworks, Flash, FlashCast, FlashHelp, Flash Lite, FlashPaper, Flash Video Encoder, Flex, Flex Builder, Fontographer, FreeHand, Generator, HomeSite, JRun, MacRecorder, Macromedia, MXML, RoboEngine, RoboHelp, RoboInfo, RoboPDF, Roundtrip, Roundtrip HTML, Shockwave, SoundEdit, Studio MX, UltraDev, and WebHelp are either registered trademarks or trademarks of Macromedia, Inc. and may be registered in the United States or in other jurisdictions including internationally. Other product names, logos, designs, titles, words, or phrases mentioned within this publication may be trademarks, service marks, or trade names of Macromedia, Inc. or other entities and may be registered in certain jurisdictions including internationally.
Third-Party Information
This guide contains links to third-party websites that are not under the control of Macromedia, and Macromedia is not responsible for the content on any linked site. If you access a third-party website mentioned in this guide, then you do so at your own risk. Macromedia provides these links only as a convenience, and the inclusion of the link does not imply that Macromedia endorses or accepts any responsibility for the content on those third-party sites.
Sorenson™ Spark™ video compression and decompression technology licensed from Sorenson Media, Inc.
Copyright © 2002-2005 Macromedia, Inc. All rights reserved. This manual may not be copied, photocopied, reproduced, translated, or converted to any electronic or machine-readable form in whole or in part without written approval from Macromedia, Inc. Notwithstanding the foregoing, the owner or authorized user of a valid copy of the software with which this manual was provided may print out one copy of this manual from an electronic version of this manual for the sole purpose of such owner or authorized user learning to use such software, provided that no part of this manual may be printed out, reproduced, distributed, resold, or transmitted for any other purposes, including, without limitation, commercial purposes, such as selling copies of this documentation or providing paid-for support services.
Acknowledgments
Project Management: Suzanne Smith
Writing: Jody Bleyle
Managing Editor: Rosana Francescato
Editing: Geta Carlson
Production Management: Patrice O’Neill
Media Design and Production: Adam Barnett, Aaron Begley, Mario Reynoso, Paul Benkman, John Franics
Special thanks to Erick Vera and the Flash Media Server engineering and QA teams.
First Edition: October 2005
Macromedia, Inc. 601 Townsend St.
San Francisco, CA 94103
Contents
Chapter 1: Client-Side ActionScript Language Reference. . . . . . . 5
ActionScript classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
ActionScript elements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Camera class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Microphone class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
MovieClip class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
NetConnection class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
NetStream class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .76
SharedObject class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
System class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Video class. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .139
Appendix A: Client-Side Information Objects . . . . . . . . . . . . . . .149
Camera information objects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
LocalConnection information objects . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
Microphone information objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
NetConnection information objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . .152
NetStream information objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .153
SharedObject information objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .156
3
4Contents
CHAPTER 1
Client-Side ActionScript Language Reference
Macromedia Flash Media Server provides two application program interfaces (APIs): a Client­Side Media ActionScript API and a Server-Side Media ActionScript API. This guide explains the client-side API.
This document is designed to be used in combination with the ActionScript documentation included with Macromedia Flash. Refer to the Flash documentation for general scripting information. Use this document to add Flash Media Server functionality to your Flash applications.
For additional information about developing applications for Flash Media Server and to understand how objects created on the client-side are paired with those on the server-Rside, see Developing Media Applications.
NOTE
Most sample code in this document uses ActionScript 2.0 syntax.
1
ActionScript classes
The following table lists all the classes in this guide, Client-Side ActionScript Language Reference for Flash Media Server 2:
ActionScript class Description
Camera class Lets you capture video from a video camera attached to the
computer that is running Macromedia Flash Player.
Microphone class Lets you capture audio from a microphone attached to the
computer that is running Flash Player.
MovieClip class Lets you specify whether an audio source is to be played locally
(Microphone object) or streamed from Flash Media Server (NetStream object).
5
ActionScript class Description
NetConnection class Manages a bidirectional connection between Flash Player and a
server, which lets you connect to Flash Remoting or to Flash Media Server.
NetStream class Opens a one-way streaming connection between Flash Player
and Flash Media Server through a connection made available by a NetConnection object.
SharedObject class Allows real-time data sharing between multiple client SWF files
and objects that are persistent on the local or remote location.
System class The System class contains properties related to certain
operations that take place on the user's computer, such as operations with shared objects, local settings for cameras and microphones, and use of the Clipboard.
Video class Lets you display live or recorded streaming video on the Stage
without embedding it in your SWF file.
ActionScript elements
Entries in this document are alphabetical by class name and then by method, property, or event handler name. The following table lists all classes, methods, properties, and event handlers individually in alphabetical order.
ActionScript element See entry
activityLevel
attachAudio
attachVideo
bandwidth
bufferLength
bufferTime
call
clear
close
connect
currentFps
data
Camera.activityLevel
MovieClip.attachAudio()
NetStream.attachVideo()
Camera.bandwidth
NetStream.bufferLength
NetStream.bufferTime
NetConnection.call()
SharedObject.clear()
NetConnection.close() SharedObject.close()
NetConnection.connect()
Camera.currentFps
SharedObject.data
, Microphone.activityLevel
, NetStream.attachAudio()
, Video.attachVideo()
, Video.clear()
, NetStream.close(),
, SharedObject.connect()
, NetStream.currentFps
6 Client-Side ActionScript Language Reference
ActionScript element See entry
deblocking
flush
fps
gain
get
getLocal
getRemote
getSize
height
index
isConnected
keyFrameInterval
loopback
liveDelay
motionLevel
Video.deblocking
SharedObject.flush()
Camera.fps
Microphone.gain
Camera.get()
SharedObject.getLocal()
SharedObject.getRemote()
SharedObject.getSize()
Camera.height
Camera.index
NetConnection.isConnected
Camera.keyFrameInterval
Camera.loopback
NetStream.liveDelay
Camera.motionLevel
, Microphone.get()
, Video.height
, Microphone.index
motionTimeOut
muted
name
names
onActivity
onCuePoint
onMetaData
onPlayStatus
onStatus
onSync
pause
play
publish
quality
Camera.motionTimeOut
Camera.muted
Camera.name
Camera.names
Camera.onActivity
NetStream.onCuePoint
NetStream.onMetaData
NetStream.onPlayStatus
Camera.onStatus NetStream.onStatus, SharedObject.onStatus
SharedObject.onSync
NetStream.pause()
NetStream.play()
NetStream.publish()
Camera.quality
, Microphone.muted
, Microphone.name
, Microphone.names
, Microphone.onActivity
, Microphone.onStatus, NetConnection.onStatus,
ActionScript elements 7
ActionScript element See entry
rate
receiveAudio
receiveVideo
seek
send
setBufferTime
setFps
setGain
setKeyFrameInterval
setLoopback
setMode
setMotionLevel
setQuality
setRate
setSilenceLevel
Microphone.rate
NetStream.receiveAudio()
NetStream.receiveVideo()
NetStream.seek()
NetStream.send()
NetStream.setBufferTime()
SharedObject.setFps()
Microphone.setGain()
Camera.setKeyFrameInterval()
Camera.setLoopback()
Camera.setMode()
Camera.setMotionLevel()
Camera.setQuality()
Microphone.setRate()
Microphone.setSilenceLevel()
, SharedObject.send()
setUseEchoSuppression
showSettings
silenceLevel
silenceTimeout
smoothing
time
uri
useCodepage
useEchoSuppression
width
Microphone.setUseEchoSuppression()
System.showSettings()
Microphone.silenceLevel
Microphone.silenceTimeout
Video.smoothing
NetStream.time
NetConnection.uri
System.useCodepage
Microphone.useEchoSuppression
Camera.width
Camera class
Availability
Flash Player 6.
Flash Media Server (not required).
, Video.width
8 Client-Side ActionScript Language Reference
The Camera class lets you capture video from a video camera attached to the computer that is running Macromedia Flash Player. When used with Flash Media Server, this class lets you transmit, display, and optionally record the video being captured. With these capabilities, you can develop media applications such as video conferencing, instant messaging with video, and so on. Flash provides similar audio capabilities; for more information, see the Microphone
class entry.
You can also use a Camera object without a server—for example, to monitor a video feed from a webcam attached to your local system.
NOTE
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.
Method summary for the Camera class
Method Description
Camera.get() Returns a reference to a Camera object for capturing
video.
Camera.setKeyFrameInterval() Specifies which video frames are transmitted in full
instead of being interpolated by the video compression algorithm.
Camera.setLoopback() Specifies whether to use a compressed video stream for a
local view of what the camera is transmitting.
Camera.setMode() Sets aspects of the camera capture mode, including
height, width, and frames per second.
Camera.setMotionLevel() Specifies how much motion is required to invoke
Camera.onActivity(true).
Camera.setQuality() Sets the maximum amount of bandwidth per second or
the required picture quality of the current outgoing video feed.
Camera class 9
Property summary for the Camera class
Property (read-only) Description
Camera.activityLevel A numeric value from 0 to 100 that specifies the amount of
motion the camera is detecting.
Camera.bandwidth The maximum amount of bandwidth the current outgoing
video feed can use, in bytes.
Camera.currentFps The rate at which the camera is capturing data, in frames per
second.
Camera.fps The rate at which you would like the camera to capture data, in
frames per second.
Camera.height The current capture height, in pixels.
Camera.index The index of the camera, as reflected in the array returned by
Camera.names.
Camera.keyFrameInterval A number that specifies which video frames are transmitted in
full instead of being interpolated by the video compression algorithm.
Camera.loopback A Boolean value that specifies whether a local view of what
the camera is capturing is compressed or uncompressed.
Camera.motionLevel A numeric value from 0 to 100 that specifies the amount of
motion required to invoke
Camera.motionTimeOut The number of milliseconds between the time the camera
Camera.onActivity(true).
stops detecting motion and the time
Camera.onActivity(false) is invoked.
Camera.muted A Boolean value that specifies whether the user has allowed
or denied access to the camera.
Camera.name The name of the camera as specified by the camera hardware.
Camera.names Class property; an array of strings containing the names of all
available video capture devices, including video capture cards and cameras.
Camera.quality A number that specifies the current level of picture quality
based on the amount of compression being applied to each video frame.
Camera.width The current capture width, in pixels.
10 Client-Side ActionScript Language Reference
Event handler summary for the Camera class
Method Description
Camera.onActivity Invoked when the camera starts or stops detecting motion.
Camera.onStatus Invoked when the user allows or denies access to the camera.
Constructor for the Camera class
See Camera.get().
Camera.activityLevel
Availability
Flash Player 6.
Flash Media Server (not required).
Usage
public activityLevel : Number [read-only]
Description
Property (read-only); 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
If the camera is available but is not yet being used because neither
NetStream.attachVideo() has been called, this property is set to -1.
Camera.setMotionLevel().
Video.attachVideo() nor
If you are streaming only uncompressed local video—that is, you are not streaming the video within a NetStream object and you have not called property is set only if you have assigned a function to the
Camera.setLoopback()(true)—this
Camera.onActivity event handler.
Otherwise, it is undefined.
See also
Camera.motionLevel, Camera.onActivity, Camera.setMotionLevel()
Camera class 11
Camera.bandwidth
Availability
Flash Player 6.
Flash Media Server (not required).
Usage
public bandwidth : Number [read-only]
Description
Property (read-only); 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().
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 component instance to the Stage and give it the instance name
my_video. Add a NumericStepper
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);
12 Client-Side ActionScript Language Reference
The MovieClip.getNextHighestDepth() method used in this example requires Flash Player 7 or later. If your SWF file includes a v2 component (version 2 of the Macromedia Component Architecture), use the DepthManager class from the component framework instead of the
See also
Camera.setQuality()
MovieClip.getNextHighestDepth() method.
Camera.currentFps
Availability
Flash Player 6.
Flash Media Server (not required).
Usage
public currentFps : Number [read-only]
Description
Property (read-only); the rate at which the camera is capturing data, in frames per second. This property cannot be set; however, you can use property—
Camera.fps—which specifies the maximum frame rate at which you would like
the camera to capture data.
Camera.setMode() to set a related
Example
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 the instance name
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)";
my_video. Add a ProgressBar component instance to the Stage and give it fps_pb. Then add the following ActionScript to Frame 1 of the Timeline:
Camera class 13
See also
Camera.fps, Camera.setMode()
Camera.fps
Availability
Flash Player 6.
Flash Media Server (not required).
Usage
public fps : Number [read-only]
Description
Property (read-only); 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.
To set a desired value for this property, use Camera.setMode().
To determine the rate at which the camera is currently capturing data, use
Camera.currentFps.
Example
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 the instance name
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() method does not guarantee the requested fps setting; it sets the fps you requested or the fastest fps available.
my_video. Add a ProgressBar component instance to the Stage and give it fps_pb. Then add the following ActionScript to Frame 1 of the Timeline:
14 Client-Side ActionScript Language Reference
See also
Camera.currentFps, Camera.setMode()
Camera.get()
Availability
Flash Player 6.
Flash Media Server (not required).
Usage
public static get([index:Number]) : Camera
NOTE
To assign the Camera object to a variable, use the following syntax:
var active_cam:Camera = Camera.get().
Parameters
index An optional zero-based integer that specifies which camera driver to get, as
determined from the array returned by (which is recommended for most applications), omit this parameter.
Camera.names. To get the default camera driver
Returns
If index is not specified, this method returns a reference to the default camera driver or, if
it is in use by another application, to the first available camera driver. (If there is more than one camera driver installed, the user may specify the default camera driver in the Flash Player Camera Settings panel.) If no camera drivers are available or installed, the method returns
If index is specified, this method returns a reference to the requested camera driver, or
null if it is not available.
Description
null.
Method; returns a reference to a Camera object for capturing video. To actually begin capturing the video, you must attach the Camera object either to a Video object (see
Video.attachVideo()) or to a NetStream object (see NetStream.attachVideo()). (The
NetStream object is available only with Flash Media Server.)
NOTE
The Camera.get() method returns a reference to a camera driver, not to a physical camera.
Camera class 15
Unlike objects that you create using the new constructor, multiple calls to Camera.get() reference the same camera driver. Thus, if your script contains the lines
cam1 = Camera.get() and cam2 = Camera.get(), both cam1 and cam2 reference the same
(default) camera driver.
In general, you shouldn’t pass a value for
index; simply use Camera.get() to return a
reference to the default camera driver. By means of the Camera settings panel (discussed later in this section), the user can specify the default camera driver Flash should use. If you pass a value for prefers. You might use
index, you might be trying to reference a camera driver other than the one the user
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 you issue
NetStream.attachVideo() or Video.attachVideo()—Flash Player displays a
Camera.get()—for example, when
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 by 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
Camera.muted.
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 and selecting Settings. When the Privacy dialog box opens, the user selects Remember.
You can’t use ActionScript to set the Allow or Deny value for a user, but you can display the Privacy dialog box 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 driver to be referenced by
System.showSettings(3).
16 Client-Side ActionScript Language Reference
Camera.get(), use
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 Flash 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.
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 instance name 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);
my_video. Add a Label component instance to the Stage and give it the
camera_lbl, and a ComboBox component instance and give it the instance
See also
Camera.index, Camera.muted, Camera.names, Camera.onStatus, Camera.setMode(), NetStream.attachVideo(), System.showSettings(), Video.attachVideo()
Camera class 17
Camera.height
Availability
Flash Player 6.
Flash Media Server (not required).
Usage
public height : Number [read-only]
Description
Property (read-only); the current capture height, in pixels. To set a value for this property, use
Camera.setMode().
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().
See also
Camera.setMode(), Camera.width
Camera.index
Availability
Flash Player 6.
Flash Media Server (not required).
18 Client-Side ActionScript Language Reference
Usage
active_cam.index
Description
Property (read-only); a zero-based integer that specifies the index of the camera, as reflected in the array returned by
Example
Camera.names.
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 instance name
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; }
my_video. Add a Label component instance to the Stage and give it the camera_lbl. Then add the following ActionScript to Frame 1 of the Timeline:
The MovieClip.getNextHighestDepth() method used in this example requires Flash Player 7 or later. If your SWF file includes a v2 component (version 2 of the Macromedia Component Architecture), use the DepthManager class from the component framework instead of the
See also
Camera.get(), Camera.names
MovieClip.getNextHighestDepth() method.
Camera class 19
Camera.keyFrameInterval
Availability
Flash Player 6.
Flash Media Server (not required).
Usage
public keyFrameInterval : Number [read-only]
Description
Property (read-only); 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 (every 15th frame is a keyframe).
See also
Camera.setKeyFrameInterval()
Camera.loopback
Availability
Flash Player 6.
Flash Media Server (not required).
Usage
public loopback : Boolean [read-only]
Description
Property (read-only); a Boolean value that specifies whether a local view of what the camera is capturing is compressed and decompressed as it would be for live transmission using Flash Media Server (
true) or uncompressed (false). The default value is false.
To set this value, use Camera.setLoopback(). To set the amount of compression used when this property is
Example
true, use Camera.setQuality().
See the example for Camera.setLoopback().
See also
Camera.setLoopback(), Camera.setQuality()
20 Client-Side ActionScript Language Reference
Camera.motionLevel
Availability
Flash Player 6.
Flash Media Server (not required).
Usage
public motionLevel : Number [read-only]
Description
Property (read-only); 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 information, see
Camera.setMotionLevel().
motionLevel property. For more
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 and give it the instance name
motionLevel_nstep, and a ProgressBar with the instance name motion_pb. Then add the
my_video. Add a Label component instance to the Stage
motionLevel_lbl, a NumericStepper with the instance name
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. */
Camera class 21
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);
See also
Camera.activityLevel, Camera.onActivity, Camera.onStatus,
Camera.setMotionLevel()
Camera.motionTimeOut
Availability
Flash Player 6.
Flash Media Server (not required).
Usage
public motionTimeOut : Number [read-only]
Description
Property (read-only); the number of milliseconds between the time the camera stops detecting motion and the time (2 seconds).
To set this value, use
Camera.onActivity(false) is invoked. The default value is 2000
Camera.setMotionLevel().
22 Client-Side ActionScript Language Reference
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 instance name
motionTimeOut_nstep, and a ProgressBar with the instance name motion_pb. Then add the
my_video. Add a Label component instance to the Stage and give it the
motionLevel_lbl, a NumericStepper with the instance name
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;
See also
Camera.onActivity, Camera.setMotionLevel()
Camera class 23
Camera.muted
Availability
Flash Player 6.
Flash Media Server (not required).
Usage
public muted : Boolean [read-only]
Description
Property (read-only); a Boolean value that specifies whether the user has denied access to the camera ( value changes,
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 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) {
trace("User denied access to Camera"); System.showSettings(0); } };
true) or allowed access (false) in the Flash Player Privacy dialog box. When this
Camera.onStatus is invoked. For more information, see Camera.get().
my_video. Then add the following
/* 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).*/
See also
Camera.get(), Camera.onStatus
24 Client-Side ActionScript Language Reference
Camera.name
Availability
Flash Player 6.
Flash Media Server (not required).
Usage
public name : String [read-only]
Description
Property (read-only); a string that specifies the name of the current camera, as returned by the camera hardware.
Example
The following example displays the name of the default camera in a text field and writes the name to the log file. In Windows, this name is the same as the device name listed in the Camera Settings 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 ActionScript to Frame 1 of the Timeline:
my_video. Then add the following
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 v2 component (version 2 of the Macromedia Component Architecture), use the DepthManager class from the component framework instead of the
See also
Camera.get(), Camera.names
MovieClip.getNextHighestDepth() method.
Camera class 25
Camera.names
Availability
Flash Player 6.
Flash Media Server (not required).
Usage
public static names : Array [read-only]
NOTE
The correct syntax is Camera.names. To assign the return value to a variable, use syntax like
var cam_array:Array = Camera.names. To determine the name of the current camera,
active_cam.name, where active_cam is the variable to which you assigned the results
use of
Camera.get().
Description
Class property (read-only); retrieves an array of strings reflecting the names of all available video capture devices (including video capture cards and cameras) without displaying the Flash Player Privacy dialog box. This array behaves the same as any other ActionScript array, implicitly providing the zero-based index of each camera driver and the number of camera drivers on the system (by means of Array class entry in the ActionScript 2.0 Language Reference.
Camera.names.length). For more information, see the
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.
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, 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);
See also
Camera.get(), Camera.index, Camera.names
26 Client-Side ActionScript Language Reference
Camera.onActivity
Availability
Flash Player 6.
Flash Media Server (not required).
Usage
public onActivity = function(activity:Boolean) {}
Parameters
activity A Boolean value set to true when the camera starts detecting motion, false
when it stops.
Returns
Nothing.
Description
Event handler; 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().
Example
The following example displays true or false in the Output panel when the camera starts or stops detecting motion:
// assumes a Video object named "my_video" is on the Stage var active_cam:Camera = Camera.get(); my_video.attachVideo(active_cam); active_cam.setMotionLevel(10, 500); active_cam.onActivity = function(mode) {
trace(mode);
}
See also
Camera.setMotionLevel()
Camera class 27
Camera.onStatus
Availability
Flash Player 6.
Flash Media Server.
Usage
public onStatus = function(infoObject:Object) {}
Parameters
infoObject A parameter defined according to the status message. For more information
about this parameter, see “Camera information objects” on page 151.
Returns
Nothing.
Description
Event handler; invoked when one of the following events occurs:
The user allows access to the camera. The Camera.muted property is set to false, and
this handler is invoked with an information object whose
Camera.Unmuted.
code property is
The user denies access to the camera. The Camera.muted property is set to true, and this
handler is invoked with an information object whose
code property is Camera.Muted.
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().
If you want to respond to this event handler, you must create a function to process the information object generated by the camera. For more information, see Appendix A, “Client-
Side Information Objects,” on page 149.
28 Client-Side ActionScript Language Reference
Example
The following event handler displays a message whenever the user allows or denies access to the camera:
// assumes a Video object named "my_video" is on the Stage var active_cam:Camera = Camera.get(); my_video.attachVideo(active_cam); active_cam.onStatus = function(infoMsg) {
if(infoMsg.code == "Camera.Muted"){
trace("User denies access to the camera"); } else
trace("User allows access to the camera");
} // Change the Allow or Deny value to invoke the function. System.showSettings(0);
See also
Camera.get(), Camera.muted, System.showSettings()
Camera.quality
Availability
Flash Player 6.
Flash Media Server (not required).
Usage
public quality : Number [read-only]
Description
Property (read-only); 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.
Camera class 29
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 Add a NumericStepper with the instance name
quality_nstep. Then add the following
my_video.
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);
See also
Camera.setQuality()
Camera.setKeyFrameInterval()
Availability
Flash Player 6.
Flash Media Server (not required).
Usage
public setKeyFrameInterval(keyframeInterval : Number) : Void
Parameters
keyframeInterval A numeric value that specifies which video frames are transmitted in
full (called keyframes) instead of being interpolated by the video compression algorithm. A value of 1 means that every frame is a keyframe, a value of 3 means that every third frame is a keyframe, and so on. Acceptable values are 1 through 48. The default value is 15.
Returns
Nothing.
30 Client-Side ActionScript Language Reference
Loading...
+ 126 hidden pages