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 eith
Contents Chapter 1: Client-Side ActionScript Language Reference. . . . . . . 5 ActionScript classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 ActionScript elements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Camera class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Microphone class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Contents
CHAPTER 1 1 Client-Side ActionScript Language Reference Macromedia Flash Media Server provides two application program interfaces (APIs): a ClientSide 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.
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.
ActionScript element See entry deblocking Video.deblocking flush SharedObject.flush() fps Camera.fps gain Microphone.gain get Camera.get(), Microphone.get() getLocal SharedObject.getLocal() getRemote SharedObject.getRemote() getSize SharedObject.getSize() height Camera.height, Video.height index Camera.index, Microphone.index isConnected NetConnection.isConnected keyFrameInterval Camera.keyFrameInterval loopback Camera.loopback liveDelay NetStream.liveDelay motionLevel Camera.
ActionScript element See entry rate Microphone.rate receiveAudio NetStream.receiveAudio() receiveVideo NetStream.receiveVideo() seek NetStream.seek() send NetStream.send(), SharedObject.send() setBufferTime NetStream.setBufferTime() setFps SharedObject.setFps() setGain Microphone.setGain() setKeyFrameInterval Camera.setKeyFrameInterval() setLoopback Camera.setLoopback() setMode Camera.setMode() setMotionLevel Camera.setMotionLevel() setQuality Camera.
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.
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.
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).
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().
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 MovieClip.getNextHighestDepth() method. See also Camera.setQuality() Camera.currentFps Availability ■ Flash Player 6. ■ Flash Media Server (not required).
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.
See also Camera.currentFps, Camera.setMode() Camera.get() Availability ■ Flash Player 6. ■ Flash Media Server (not required). Usage public static get([index:Number]) : Camera N OT E To assign the Camera object to a variable, use the following syntax: var active_cam:Camera = Camera.get(). Parameters An optional zero-based integer that specifies which camera driver to get, as determined from the array returned by Camera.names.
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.
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.
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.
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 Camera.names. 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.
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.
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 motionLevel property. For more information, see Camera.setMotionLevel().
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.
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.
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 (true) or allowed access (false) in the Flash Player Privacy dialog box. When this value changes, Camera.onStatus is invoked. For more information, see Camera.get(). Example In the following example, an error message could be displayed if my_cam.
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.
Camera.names Availability ■ Flash Player 6. ■ Flash Media Server (not required). Usage public static names : Array [read-only] NO T E 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, use active_cam.name, where active_cam is the variable to which you assigned the results of Camera.get().
Camera.onActivity Availability ■ Flash Player 6. ■ Flash Media Server (not required). Usage public onActivity = function(activity:Boolean) {} Parameters A Boolean value set to true when the camera starts detecting motion, false when it stops. activity 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.
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.
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.
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.
Description Method; 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. The Flash Video compression algorithm compresses video by transmitting only what has changed since the last frame of the video; these portions are considered to be interpolated frames.
Returns Nothing. Description Method; specifies whether to use a compressed video stream for a local view of the camera. This method is generally applicable only if you are transmitting video using the Flash Media Server; setting compressLocalStream to true lets you see more precisely how the video will appear to users when they view it in real time.
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. 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.
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.
Returns Nothing. Description Method; 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). NO T E Video can be displayed regardless of the value of the motionLevel parameter. This parameter only determines when and under what circumstances Camera.onActivity is invoked—not whether video is actually being captured or displayed.
Example The following example sends messages to the Output panel 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.
quality 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. TIP Streams compressed with the lossless codec are larger than streams compressed with the default Sorenson codec.
See also Camera.bandwidth, Camera.get(), Camera.quality Camera.width Availability ■ Flash Player 6. ■ Flash Media Server (not required). Usage public width : Number [read-only] Description Property (read-only); the current capture width, in pixels. To set a desired 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.
The Microphone class lets you capture audio from a microphone attached to the computer that is running Flash Player. When used with Flash Media Server, this class lets you transmit, play, and optionally record the audio being captured. With these capabilities, you can develop media applications such as instant messaging with audio, recording presentations so others can replay them at a later date, and so on. Flash provides similar video capabilities; for more information, see the Camera class entry.
Property (read-only) Description Microphone.muted A Boolean value that specifies whether the user has allowed or denied access to the microphone. Microphone.name The name of the current sound capture device, as returned by the sound capture hardware. Microphone.names Class property: an array of strings reflecting the names of all available sound capture devices, including sound capture cards and microphones. Microphone.rate The sound capture rate, in kHz. Microphone.
Description Property (read-only); a numeric value that specifies the amount of sound the microphone is detecting. Values range from 0 (no sound is being detected) to 100 (very loud sound is being detected). The value of this property can help you determine a good value to pass to the Microphone.setSilenceLevel() method. If the microphone is available but is not yet being used because neither MovieClip.attachAudio() nor NetStream.attachAudio() has been called, this property is set to -1.
Microphone.gain Availability ■ Flash Player 6. ■ Flash Media Server (not required). Usage public gain : Number [read-only] Description Property (read-only); the amount by which the microphone boosts the signal. Valid values are 0 to 100. The default value is 50. Example The following example uses a ProgressBar instance called gain_pb to display and a NumericStepper instance called gain_nstep to set the microphone's gain value: this.createEmptyMovieClip("sound_mc", this.
Microphone.get() Availability ■ Flash Player 6. ■ Flash Media Server (not required). Usage public static get([index:Number]) : Microphone NO T E The correct syntax is Microphone.get(). To assign the Microphone object to a variable, use syntax like var active_mic:Microphone = Microphone.get(). Parameters An optional zero-based integer that specifies which microphone to get, as determined from the array returned by Microphone.names.
When a SWF file tries to access the microphone returned by the Microphone.get() method—for example, when you issue NetStream.attachAudio() or MovieClip.attachAudio()—Flash Player displays a Privacy dialog box that lets the user choose whether to allow or deny access to the microphone. (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 Microphone.
Microphone.index Availability ■ Flash Player 6. ■ Flash Media Server (not required). Usage public index : Number [read-only] Description Property (read-only); a zero-based integer that specifies the index of the microphone, as reflected in the array returned by Microphone.names. Example The following example displays the names of the sound capturing devices available on your computer system in a ComboBox instance called mic_cb.
Microphone.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 microphone (true) or allowed access (false). When this value changes, Microphone.onStatus is invoked. For more information, see Microphone.get(). Example This example gets the default microphone and checks whether it is muted: var active_mic:Microphone = Microphone.
Example The following example displays information about the sound capture device(s) on your computer system, including an array of names and the default device: var status_ta:mx.controls.TextArea; status_ta.html = false; status_ta.setStyle("fontSize", 9); var microphone_array:Array = Microphone.names; var active_mic:Microphone = Microphone.get(); status_ta.text = "The default device is: "+active_mic.name+newline+newline; status_ta.text += "You have "+microphone_array.length+" device(s) installed.
Example The following code returns information on the array of audio devices: var allMicNames_array:Array = Microphone.names; trace("Microphone.names located these device(s):"); for(i=0; i < allMicNames_array.length; i++){ trace("[" + i + "]: " + allMicNames_array[i]); } For example, the following information could be displayed: Microphone.names located these device(s): [0]: Crystal SoundFusion(tm) [1]: USB Audio Device See also Array class entry in the ActionScript 2.0 Language Reference, Microphone.
Example The following example displays true or false in the Output panel when the microphone starts or stops detecting sound. var active_mic:Microphone = Microphone.get(); _root.attachAudio(active_mic); active_mic.onActivity = function(mode){ trace(mode); } See also Microphone.setSilenceLevel() Microphone.onStatus Availability ■ Flash Player 6. ■ Flash Media Server (not required).
When a SWF file tries to access the microphone, Flash Player displays a Privacy dialog box that lets the user choose whether to allow or deny access. ■ If the user allows access, the Microphone.muted property is set to false, and this event handler is invoked with an information object whose code property is Microphone.Unmuted. ■ If the user denies access, the Microphone.muted property is set to true, and this event handler is invoked with an information object whose code property is Microphone.Muted.
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 MovieClip.getNextHighestDepth() method. See also Microphone.get(), Microphone.muted, System.showSettings() Microphone.rate Availability ■ Flash Player 6. ■ Flash Media Server (not required).
Parameters An integer that specifies the amount by which the microphone should boost the signal. Valid values are 0 to 100. The default value is 50; however, the user may change this value in the Flash Player Microphone Settings panel. gain Returns Nothing. Description Method; sets the microphone gain—that is, the amount by which the microphone should multiply the signal before transmitting it. A value of 0 tells Flash to multiply by 0; that is, the microphone transmits no sound.
Returns Nothing. Description Method; sets the rate, in kHz, at which the microphone should capture sound. Example The following example sets the microphone rate to the user’s preference (which you have assigned to the userRate variable) if it is one of the following values: 5, 8, 11, 22, or 44. If it is not, the value is rounded to the nearest acceptable value that the sound capture device supports. active_mic.setRate(userRate); See also Microphone.rate Microphone.
Description Method; sets the minimum input level that should be considered sound and (optionally) the amount of silent time signifying that silence has actually begun. ■ To prevent the microphone from detecting sound at all, pass a value of 100 for silenceLevel; Microphone.onActivity is never invoked. ■ To determine the amount of sound the microphone is currently detecting, use Microphone.activityLevel. Activity detection is the ability to detect when audio levels suggest that a person is talking.
var silenceLevel_pb:mx.controls.ProgressBar; var silenceLevel_nstep:mx.controls.NumericStepper; this.createEmptyMovieClip("sound_mc", this.getNextHighestDepth()); var active_mic:Microphone = Microphone.get(); sound_mc.attachAudio(active_mic); silenceLevel_pb.label = "Activity level: %3"; silenceLevel_pb.mode = "manual"; silenceLevel_nstep.minimum = 0; silenceLevel_nstep.maximum = 100; silenceLevel_nstep.value = active_mic.silenceLevel; var nstepListener:Object = new Object(); nstepListener.
Microphone.setUseEchoSuppression() Availability ■ Flash Player 6. ■ Flash Media Server (not required). Usage public setUseEchoSuppression(suppress : Boolean) : Void Parameters suppress A Boolean value indicating whether echo suppression should be used (true) or not (false). Returns Nothing. Description Method; specifies whether to use the echo suppression feature of the audio codec. The default value is false unless the user has selected Reduce Echo in the Flash Player Microphone Settings panel.
Example The following example turns on echo suppression if the user selects a CheckBox instance called useEchoSuppression_ch. The ProgressBar instance called activityLevel_pb displays the current activity level of the audio stream. var useEchoSuppression_ch:mx.controls.CheckBox; var activityLevel_pb:mx.controls.ProgressBar; this.createEmptyMovieClip("sound_mc", this.getNextHighestDepth()); var active_mic:Microphone = Microphone.get(); sound_mc.attachAudio(active_mic); activityLevel_pb.
Example The following example changes the silence level based on the user's input in a NumericStepper instance called silenceLevel_nstep. The ProgressBar instance called silenceLevel_pb modifies its appearance depending on whether the audio stream is considered silent. If the audio stream is not silent, the progress bar displays the activity level of the audio stream. var silenceLevel_pb:mx.controls.ProgressBar; var silenceLevel_nstep:mx.controls.NumericStepper; this.createEmptyMovieClip("sound_mc", this.
See also Microphone.gain, Microphone.onActivity, Microphone.setSilenceLevel() Microphone.silenceTimeout Availability ■ Flash Player 6. ■ Flash Media Server (not required). Usage public silenceTimeout : Number [read-only] Description Property (read-only); a numeric value representing the number of milliseconds between the time the microphone stops detecting sound and the time Microphone.onActivity(false) is invoked. The default value is 2000 (2 seconds). To set this value, use Microphone.
silenceTimeOut_nstep.addEventListener("change", nstepListener); this.onEnterFrame = function() { silenceLevel_pb.setProgress(active_mic.activityLevel, 100); }; active_mic.onActivity = function(active:Boolean) { if (active) { silenceLevel_pb.indeterminate = false; silenceLevel_pb.setStyle("themeColor", "haloGreen"); silenceLevel_pb.label = "Activity level: %3"; } else { silenceLevel_pb.indeterminate = true; silenceLevel_pb.setStyle("themeColor", "0xFF0000"); silenceLevel_pb.
Example The following example turns on echo suppression if the user selects a CheckBox instance called useEchoSuppression_ch. The ProgressBar instance called activityLevel_pb displays the current activity level of the audio stream. var useEchoSuppression_ch:mx.controls.CheckBox; var activityLevel_pb:mx.controls.ProgressBar; this.createEmptyMovieClip("sound_mc", this.getNextHighestDepth()); var active_mic:Microphone = Microphone.get(); sound_mc.attachAudio(active_mic); activityLevel_pb.
MovieClip.attachAudio() Availability ■ Flash Player 6. ■ Flash Media Server (not required). Usage public attachAudio(source : Object) : Void Parameters source The object containing the audio to play. Valid values are a Microphone object, a NetStream object (requires Flash Media Server), and false (stops playing the audio). N OT E In Flash Player 7 and later, source can also be a NetStream object playing an FLV file without the use of Flash Media Server.
Example The following example creates a new NetStream connection. Add a new Video symbol by opening the Library panel and selecting New Video from the Library options menu. Give the symbol the instance name my_video. Dynamically load the FLV video at runtime. Use the attachAudio() method to attach the audio from the FLV file to a movie clip on the Stage. Then you can control the audio in the movie clip by using the Sound class and two buttons called volUp_btn and volDown_btn.
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 MovieClip.getNextHighestDepth() method. See also Microphone class, NetStream class, NetStream.attachAudio(), Sound class in ActionScript 2.0 Language Reference NetConnection class Availability ■ Flash Player 6.
Method summary for the NetConnection class Method Description NetConnection.call() Invokes a command or method on the server. NetConnection.close() Closes the connection with the server. NetConnection.connect() Connects to an application on the Flash Media Server. Property summary for the NetConnection class Property (read-only) Description NetConnection.
Description Constructor; creates an object that can be used to connect Flash Player to the Flash Media Server or to an application server. After creating the NetConnection object, use NetConnection.connect() to make the actual connection. For information on using Flash with an application server, see http://www.macromedia.com/ go/flashmediaserver_desdev_en.
For security reasons, certain remoteMethod names are reserved at the application level; do not call these method names with the NetConnection.call method(). The reserved names are / onConnect, /onDisconnect, /onStatus, /onAppStop, and /onAppStart. An object parameter that is needed only when the sender is expecting a result. The result object can be any user-defined object. For it to be of use, a handler named onResult must be called when the result arrives. If you don’t need a result object, pass null.
Description Method; closes the connection with the server and invokes NetConnection.onStatus with a code property of NetConnection.Connect.Close. For more information, see NetConnection.onStatus. This method disconnects all NetStream objects running over this connection; any queued data that has not been sent is discarded. (To terminate server streams without closing the connection, use NetStream.close().
Parameters The Uniform Resource Identifier (URI) of the application on the Flash Media Server that runs when the connection is made. For targetURI, use the following general format (items in brackets are optional): targetURI protocol:[//host][:port]/appname/[instanceName] For protocol, specify either rtmp, rtmpt, or rtmps. If rtmp is specified, Flash Player will create a persistent socket connection with Flash Media Server.
In general, use the RTMP protocol, which opens a persistent connection between Flash Player and Flash Media Server. If, however, clients are connecting from behind a firewall or through HTTP proxy servers that prohibit direct RTMP socket connections, use the RTMPT protocol, which transmits RTMP data over an HTTP connection. The RTMPT protocol explicitly requests an HTTP connection and enables a faster connection time for clients who can’t connect through RTMP. RTMPS connections use port 443 by default.
Because of network and thread timing issues, it is better to place a NetConnection.onStatus handler in a script before a NetConnection.connect() method. Otherwise, the connection might complete before the script executes the onStatus handler initialization. Also, all security checks are made within the NetConnection.connect() method, and notifications will be lost if the onStatus handler is not yet set up.
In another case, you may have an application named lectureSeries that records and plays back classroom lectures. To save individual lectures, pass a different value for instanceName each time you record a lecture, as shown in the following example: // Record Monday’s lecture. my_nc.connect("rtmp://www.myserver.com/lectureSeries/Monday"); // Later ... my_ns.connect(my_nc); my_ns.publish("lecture", "record"); // Record Tuesday’s lecture. my_nc.connect("rtmp://www.myserver.
There are a few things you can do to prevent the security policies from inconveniencing you or your users. The first, and easiest, is to use a target URI that doesn’t specify a server name. (This is applicable only if the Flash Media Server and web server are running from the same IP address.) To do so, leave off the second slash in the targetURI parameter.
The following example opens a connection to play the video2.flv file. Select New Video from the Library options menu to create a new Video object, and give it the instance name my_video. var connection_nc:NetConnection = new NetConnection(); connection_nc.connect(null); var stream_ns:NetStream = new NetStream(connection_nc); my_video.attachVideo(stream_ns); stream_ns.play("video2.flv"); See also NetConnection.close(), NetConnection.onStatus NetConnection.isConnected Availability ■ Flash Player 6.
NetConnection.onStatus Availability ■ Flash Player 6. ■ Flash Communication Server MX 1.0. Usage my_nc.onStatus = function(infoObject) { // your code here } Parameters infoObject A parameter defined according to the status message. For more information about this parameter, see “NetConnection information objects” on page 152. Returns Nothing. Description Event handler; invoked when a status change or error is posted for the NetConnection object.
Usage my_nc.uri Description Property (read-only); a string representing the target URI that was passed in with NetConnection.connect(). If NetConnection.connect() hasn’t yet been called for my_nc, this property is undefined. See also NetConnection.connect() NetStream class Availability ■ Flash Player 6. ■ Flash Communication Server MX 1.0. NO TE In Flash Player 7 and later, you can use this method to play FLV files without Flash Media Server.
5. Use NetStream.publish(publishName:String) to give this stream a unique name and send data over the stream to the Flash Media Server, so others can receive it. You can also record the data as you publish it, so that users can play it back later. SWF files that subscribe to this stream will use the name specified here; that is, they will call the same NetConnection.connect() method as the publisher, and then call a NetStream.play(publishName:Object) method. They will also have to call Video.
Method summary for the NetStream class Method Description NetStream.attachAudio() Publisher method; specifies whether audio should be sent over the stream. NetStream.attachVideo() Publisher method; starts transmitting video or a snapshot from the specified source. NetStream.close() Stops publishing or playing all data on the stream and makes the stream available for another use. NetStream.pause() Subscriber method; pauses or resumes playback of a stream. NetStream.
Property summary for the NetStream class Property (read-only) Description NetStream.bufferLength The number of seconds of data currently in the buffer. NetStream.bufferTime The number of seconds assigned to the buffer by NetStream.setBufferTime(). NetStream.currentFps The number of frames per second being sent or received on the publishing or subscribing stream. NetStream.liveDelay The number of seconds of data in a subscribing stream’s buffer in live mode. NetStream.
Returns A NetStream object. Description Constructor; creates a stream that can be used for publishing (sending) or playing (receiving) data through the specified NetConnection object. You can’t publish and play data over the same stream at the same time. For example, if you are publishing on a stream and then call NetStream.play(), an implicit NetStream.close() method is called; the publishing stream then becomes a subscribing stream.
NetStream.attachAudio() Availability ■ Flash Player 6. ■ Flash Communication Server MX 1.0. Usage public attachAudio(source:Microphone) : Void Parameters source The source of the audio to be transmitted. Valid values are a Microphone object and null. Returns Nothing. Description Method; specifies whether audio should be sent over the stream (from a Microphone object passed as source) or not (null passed as source). This method is available only to the publisher of the specified stream.
NetStream.attachVideo() Availability ■ Flash Player 6. ■ Flash Communication Server MX 1.0. Usage public attachVideo(source : Camera [, snapShotMilliseconds : Number]) Parameters source The source of the video transmission. Valid values are a Camera object (which starts capturing video) and null. If you pass null, Flash stops capturing video, and any additional parameters you send are ignored.
After attaching the video source, you must call NetStream.publish() to actually begin transmitting. Subscribers who want to display the video must call the NetStream.play() and Video.attachVideo() methods to display the video on the Stage. You can use snapShotMilliseconds to send a single snapshot (by providing a value of 0) or a series of snapshots—in effect, time-lapse footage—by providing a positive number that adds a trailer of the specified number of milliseconds to the video feed.
Example The following function publishes a stream on a NetConnection named my_nc containing the camera output from active_cam. function pubLive() { // Create a new source stream. var source_ns:NetStream = new NetStream(my_nc); /* Attach the camera activity to the source stream. This call causes a warning message to show which service is requesting access. It also gives the user the option of not sending the camera activity to the server. */ source_ns.
Example The following example dynamically creates a text field that displays information about the number of seconds that are currently in the buffer. The text field also displays the buffer length that the video is set to, and percentage of buffer that is filled. this.createTextField("buffer_txt", this.getNextHighestDepth(), 10, 10, 300, 22); buffer_txt.html = true; var connection_nc:NetConnection = new NetConnection(); connection_nc.
Description Property (read-only); the number of seconds assigned to the buffer by NetStream.setBufferTime(). The default value is 9. To determine the number of seconds currently in the buffer, use NetStream.bufferLength. NO T E The default value for Flash Media Server bufferTime property is different from the default value for the standard ActionScript bufferTime property.
NetStream.close() Availability ■ Flash Player 6. ■ Flash Communication Server MX 1.0. Usage public close() : Void Parameters None. Returns Nothing. Description Method; stops publishing or playing all data on the stream, sets the NetStream.time property to 0, and makes the stream available for another use. This method is invoked implicitly whenever you call NetStream.play() from a publishing stream, or NetStream.publish() from a subscribing stream.
See also NetStream.pause(), NetStream.play(), NetStream.publish(), NetStream.time NetStream.currentFps Availability ■ Flash Player 6. ■ Flash Communication Server MX 1.0. Usage public currentFps : Number [read-only] Description Property (read-only); the number of frames per second being sent or received on the specified publishing or subscribing stream. NetStream.liveDelay Availability ■ Flash Player 6. ■ Flash Communication Server MX 1.0.
Example The following example displays a string (inside a text field named connectionQuality_str) indicating the connection quality over the NetStream object named my_ns, according to the value of the liveDelay property. if (my_ns.liveDelay < .5) { connectionQuality_str.text } else if (my_ns.liveDelay < connectionQuality_str.text } else { connectionQuality_str.text } = "Good"; 1) { = "Slow"; = "Network congested"; NetStream.onCuePoint Availability ■ Flash Player 8. ■ Flash Media Server 2.
Returns Nothing. Description Event handler; invoked when an embedded cue point is reached while an FLV file is playing. You can use this handler to trigger actions in your code when the video reaches a specific cue point. This lets you synchronize other actions in your application with video playback events.
Example The code in this example starts by creating new NetConnection and NetStream objects. Then it defines the onCuePoint handler for the NetStream object. The handler cycles through each named property in the infoObject object and prints the property's name and value. When it finds the property named parameters, it cycles through each parameter name in the list and prints the parameter name and value. var nc:NetConnection = new NetConnection(); nc.connect(null); var ns:NetStream = new NetStream(nc); ns.
The code in this example causes the following information to be displayed: onCuePoint: parameters = lights: beginning type = navigation time = 0.418 name = point1 --------onCuePoint: parameters = lights: middle type = navigation time = 7.748 name = point2 --------onCuePoint: parameters = lights: end type = navigation time = 16.02 name = point3 --------- The parameter name lights is an arbitrary name used by the author of the example video. You can give cue point parameters any name you want.
Description Event handler; invoked when the Flash Player receives descriptive information embedded in the FLV file being played. The Flash Video Exporter utility (version 1.1 or later) embeds a video's duration, creation date, data rates, and other information into the video file itself. Different video encoders embed different sets of metadata. This handler is triggered after a call to the NetStream.play() method, but before the video playhead has advanced.
NetStream.onPlayStatus Availability ■ Flash Player 6. ■ Flash Media Server 2. Usage public onPlayStatus = function(infoObject:Object) {} Parameters infoObject An object containing an error or status message. For more information about this parameter, see “NetStream information objects” on page 153. Returns Nothing. Description Event handler; invoked when a NetStream object has completely played a stream.
NetStream.onStatus Availability ■ Flash Player 6. ■ Flash Communication Server MX 1.0. Usage public onStatus = function(infoObject:Object) {} Parameters infoObject A parameter defined according to the status or error message. For more information about this parameter, see “NetStream information objects” on page 153. Returns Nothing. Description Event handler; invoked every time a status change or error is posted for the NetStream object.
NetStream.pause() Availability ■ Flash Player 6. ■ Flash Communication Server MX 1.0. Usage public pause( [ flag : Boolean] ) : Void Parameters Optional: a Boolean value specifying whether to pause play (true) or resume play (false). If you omit this parameter, NetStream.pause() acts as a toggle: the first time it is called on a specified stream, it pauses play, and the next time it is called, it resumes play. flag Returns Nothing. Description Method; pauses or resumes playback of a stream.
In the following example, suppose you have a playlist of three recorded streams. var my_nc:NetConnection = new NetConnection(); my_nc.connect("rtmp://localhost/appName/appInstance"); // Create a NetStream for playing back in a Video object named my_video. var my_ns:NetStream = new NetStream(my_nc); my_video.attachVideo(my_ns); // to play record1 my_ns.play("record1", 0, -1, false); // to play record2 my_ns.play("record2", 0, -1, false); // to play record3 my_ns.
NetStream.play() Availability ■ Flash Player 6. ■ Flash Communication Server MX 1.0. Usage public play(name : Object [,start : Number[, len : Number[, reset : Object]]]) Parameters An identifying name for live data published by NetStream.publish(), a recorded file name for playback, or false. If you pass false, the stream stops playing and any additional parameters you send are ignored.
An optional numeric parameter that specifies the duration of the playback, in seconds. len ■ The default value for len is -1, which means that Flash plays a live stream until it is no longer available or plays a recorded stream until it ends. ■ If you pass 0 for len, Flash plays the single frame that is start seconds from the beginning of a recorded stream (assuming start is equal to or greater than 0).
You can use the optional parameters of this method to control various aspects of playback behavior. The following table shows a few ways in which these values interact: start len Flash Player behavior (Default) (Default) Plays the live stream until it is no longer available. If a live stream of the specified name is not found, Flash Player plays a recorded stream until it ends. -2 19 Plays a live stream for up to 19 seconds after it becomes available.
starting at the beginning, for up to 100 seconds*/ my_ns.play("record1", 0, 100, true); Example 2: /* To play and switch between live and recorded streams: Suppose we have two live streams, live1 and live2, and three recorded streams, record1, record2, and record3. The play order is record1, live1, record2, live2, and record3.*/ var my_nc:NetConnection = new NetConnection(); my_nc.connect("rtmp://localhost/appName/appInstance"); // Create a NetStream for playing.
NetStream.publish() Availability ■ Flash Player 6. ■ Flash Communication Server MX 1.0. Usage public publish(name : String [, howToPublish : String] ) : Void Parameters name A string value that identifies the stream. If you pass false, the publish operation stops. Subscribers to this stream must pass this same name when they call NetStream.play(). You don’t need to include a file extension for the stream name. howToPublish An optional string that specifies how to publish the stream.
You don’t use this command when you want to let a subscriber play a stream that has already been published and recorded. For example, assume you have recorded a stream named “allAboutMe.” To enable someone to play it back, you need only open a stream for the subscriber to use: var publish_ns:NetStream = new NetStream(my_nc); var subscribe_ns:NetStream = new NetStream(my_nc); subscribe_ns.
Example The following example shows how to publish and record a video, and then play it back: var my_nc:NetConnection = new NetConnection(); my_nc.connect("rtmp://myServer.myDomain.com/appName/appInstance"); var src_ns:NetStream = new NetStream(my_nc); src_ns.publish("stephen", "record"); src_ns.attachVideo(Camera.get()); // to stop publishing and recording src_ns.publish(false); // to play the recorded stream src_ns.play("stephen"); See also NetConnection.connect(), NetStream.play(), Video.
If the specified stream contains only audio data, passing a value of false to this method stops NetStream.time from further incrementing. See also NetStream.receiveVideo(), NetStream.time NetStream.receiveVideo() Availability ■ Flash Player 6. ■ Flash Communication Server MX 1.0. Usage public receiveVideo(receive : Boolean | FPS : Number) : Void Parameters A Boolean value that specifies whether incoming video plays on the specified stream (true) or not (false). The default value is true.
If you pass the FPS parameter to limit the frame rate of the video, Flash Media Server attempts to reduce the frame rate while preserving the integrity of the video. The server sends the minimum number of frames needed to satisfy the desired rate between every two keyframes. Keep in mind, however, that i-frames (or intermediate frames) must be sent contiguously; otherwise, the video will be corrupted. Therefore, the desired number of frames is sent immediately and contiguously following a keyframe.
Returns Nothing. Description Method; seeks the specified number of seconds into the recorded stream that is currently playing, either from the beginning of the stream or from the current position. This method is available only to clients subscribed to the specified stream, not to the stream’s publisher. If you require an accurate return value from seeking, you may need to change the Application.xml file’s EnhancedSeek flag on the server. is a Boolean flag in the Application.xml file.
Parameters handlerName A string value that identifies the message; also the name of the ActionScript handler to receive the message. The handler name can be only one level deep (that is, it can’t be of the form parent/child) and is relative to the stream object. NO T E Do not use a reserved term for a handler name. For example, my_ns.send("close") will fail. p1, ...,pN Optional parameters that can be of any type.
NetStream.setBufferTime() Availability ■ Flash Player 6. ■ Flash Communication Server MX 1.0. Usage public setBufferTime(bufferTime : Number) : Void Parameters bufferTime The number of seconds to be buffered before Flash stops sending data (on a publishing stream) or begins displaying data (on a subscribing stream). The default value is 9. N OT E The default value for Flash Media Server bufferTime parameter is different than the default value for the standard ActionScript bufferTime parameter.
NetStream.time Availability ■ Flash Player 6. ■ Flash Communication Server MX 1.0. Usage public time : Number [read-only] Description Property (read-only); for a subscriber stream, the number of seconds the stream has been playing; for a publishing stream, the number of seconds the stream has been publishing. This number is accurate to the thousandths decimal place; multiply by 1000 to get the number of milliseconds the stream has been playing.
my_ns.attachVideo(active_cam); // After 10 seconds, my_ns.time = 20. The following example shows how NetStream.time is reset to 0 when you stop publishing a stream for a while and then start publishing the same stream: my_ns.attachVideo(active_cam); my_ns.publish("SomeData", "live"); //After 10 seconds, my_ns.time = 10. //You then stop publishing the stream. my_ns.publish(false); //10 seconds later, you publish on the same stream. my_ns.publish("SomeData", "live"); //my_ns.time resets to 0.
SharedObject class Availability ■ Flash Player 6. ■ Flash Media Server (not required). Shared objects are quite powerful: they offer real-time data sharing between multiple client SWF files and objects that are persistent on the local or remote location. You can think of local shared objects as “cookies” and remote shared objects as real-time data transfer devices. Common ways to use shared objects are summarized below.
The following examples show a few ways shared objects are called within ActionScript programs. Notice that in order to create a remote shared object, you must first connect to Flash Media Server with the RTMP protocol. // Create a local shared object. var local_so:SharedObject = SharedObject.getLocal("foo"); // Create a remote shared object that is not persistent on the server. var my_nc:NetConnection = new NetConnection(); my_nc.connect("rtmp://server.domain.
Data design and management Data associated with shared objects are stored in attributes of the object’s data properties; each set of attributes constitutes one slot. For example, the following lines assign values to three slots of a shared object: my_so.data.userID = "myLogonName"; my_so.data.currentStatus = "in a meeting"; my_so.data.
Assign an owner A more sophisticated strategy is to define a single client as the owner of a property in a shared object for a limited period of time. You might write server code to create a “lock” object, where a client can request ownership of a slot. If the server reports that the request was successful, the client knows that it will be the only client changing the data in the shared object.
The following list summarizes how the user’s disk space choices interact with remote shared objects from a specified domain that request local persistence: ■ If the user selects Never, objects are never saved locally, and all SharedObject.flush() commands issued for the object return false. ■ If the user selects Unlimited (by moving the slider all the way to the right), objects are saved locally up to available disk space.
Method Description SharedObject.send() Broadcasts a message to all clients connected to the remote shared object, including the client that sent the message. SharedObject.setFps() Specifies the number of times per second that a client’s changes to a shared object are sent to the server. Property summary for the SharedObject class Property (read-only) Description SharedObject.data The collection of attributes assigned to the data property of the object; these attributes can be shared and/or stored.
Parameters None. Returns Nothing. Description Method; for local shared objects, purges all the data from the shared object and deletes the shared object from the disk. The reference to my_so is still active, but my_so data properties are deleted. For remote shared objects, this method disconnects the object and purges all the data; if the shared object is locally persistent, the method also deletes the shared object from the disk.
Usage myRemote_so.close() Parameters None. Returns Nothing. Description Method; closes the connection between a remote shared object and the Flash Media Server. If a remote shared object is locally persistent, the user can make changes to the local copy of the object after this method is called. Any changes made to the local object are sent to the server the next time the user connects to the remote shared object. See also SharedObject.clear(), SharedObject.connect(), SharedObject.flush() SharedObject.
Before attempting to work with a remote shared object, you should first check for a return value of true, indicating a successful connection, and then wait until you receive a result from the function you have assigned to SharedObject.onSync. If you fail to do so, any changes you make to the object locally—before SharedObject.onSync is invoked—may be lost. N OT E SharedObject.onSync is not invoked if this call returns false. See also NetConnection class, SharedObject.getRemote(), SharedObject.
All attributes of a shared object’s data property are available to all clients connected to the shared object, and all of them are saved if the object is persistent. Attributes are volatile; if one client changes the value of an attribute, all clients now see the new value. The shared object created above contains the following information: userName: Ramona adminPrivileges: true itemNumbers: 101,346,483 NO TE Do not assign values directly to the data property of a shared object, as in my_so.
SharedObject.flush() Availability ■ Flash Player 6. ■ Flash Media Server (not required). Usage myLocalOrRemote_so.flush([minimumDiskSpace]) Parameters minimumDiskSpace An optional integer specifying the number of bytes that must be allotted for this object. The default value is 0.
For example, if you expect a shared object to grow to a maximum size of 500 bytes, even though it may start out much smaller, pass 500 for minimumDiskSpace. If Flash asks the user to allot disk space for the shared object, it will ask for 500 bytes. After the user allots the requested amount of space, Flash won’t have to ask for more space on future attempts to flush the object (as long as its size doesn’t exceed 500 bytes).
For a remote shared object, calling SharedObject.flush() in the client-side ActionScript file flushes the object only on the client, not the server. The following example shows how a server-side script can flush a remote shared object on the server: // This is a SERVER-SIDE script, not ActionScript. // Get the shared object when the application is loaded. application.onAppStart = function(){ application.my_so = SharedObject.get("SharedObjName", true); } // When a user disconnects, flush the shared object.
localPath An optional string parameter that specifies the full or partial path to the SWF file that created the shared object, and that determines where the shared object will be stored locally. The default value is the full path. For more information on using this parameter, see SharedObject.getRemote(). (Flash Player 8 only) An optional Boolean value that determines whether access to this shared object is restricted to SWF files that are delivered over an HTTPS connection.
Description Method; returns a reference to a locally persistent shared object that is available only to the current client. To create a shared object that is available to multiple clients by means of the Flash Media Server, use SharedObject.getRemote(). NO T E If the user has chosen to never allow local storage for this domain, the object will not be saved locally, even if a value for localPath is specified. For more information, see “Local disk space considerations” on page 115.
// Register the listener with the TextInput component instance. myText_ti.addEventListener("enter", textListener); The following example saves the last frame that a user entered to a local shared object kookie: // Get the kookie. var my_so:SharedObject = SharedObject.getLocal("kookie"); // Get the user of the kookie and go to the frame number saved for this user. if (my_so.data.user != undefined) { this.user = my_so.data.user; this.gotoAndStop(my_so.data.
An optional value that specifies whether the attributes of the shared object’s property are persistent locally, remotely, or both, and that may specify where the shared object will be stored locally. Acceptable values are as follows: persistence data ■ null (default) or false specifies that the shared object is not persistent on the client or server. (These values have the same effect as omitting the persistence parameter.
Once a value has been passed for the local persistence of a remote shared object, it is valid for the life of the object. In other words, once you have gotten a remote shared object which is not locally persistent, you cannot get the same shared object with local persistence while the shared object is active.
Similarly, you can use persistence to let SWF files in different directories in the same domain read and write each other’s shared objects. For example, if the full path to the SWF file is www.macromedia.com/a/b/c/d/foo.swf, persistence can be any of the following: ■ "/" ■ "/a/" ■ "/a/b/" ■ "/a/b/c/" ■ "/a/b/c/d/" ■ "/a/b/c/d/foo.swf/" By specifying a partial path for persistence, you can let several SWF files from the same domain access the same shared objects.
SharedObject.getSize() Availability ■ Flash Player 6. ■ Flash Media Server (not required). Usage myLocalOrRemote_so.getSize() Parameters None. Returns A numeric value specifying the size of the shared object, in bytes. Description Method; gets the current size of the shared object, in bytes. Flash calculates the size of a shared object by stepping through each of its data properties; the more data properties the object has, the longer it takes to estimate its size.
SharedObject.onStatus Availability ■ Flash Player 6. ■ Flash Media Server (not required). Usage public onStatus = function(infoObject) {} Parameters infoObject A parameter defined according to the status message. For more information about this parameter, see “SharedObject information objects” on page 156. Returns Nothing. Description Event handler; invoked every time an error, warning, or informational note is posted for a shared object.
Parameters objArray An array of objects; each object contains properties that describe the changed members of a remote shared object. Returns Nothing. Description Event handler; initially invoked when the client and server shared object are synchronized after a successful call to SharedObject.connect(), and later invoked whenever any client changes the attributes of the data property of the remote shared object.
To minimize network traffic, this method is not called when a client “changes” a property to the same value it currently has. That is, if a property is set to the same value multiple times in a row, this method is invoked the first time the property is set, but not during subsequent settings, as shown in the following example: my_so.data.x = 15; // The following line invokes onSync. my_so.data.x = 20; /* The following line doesn’t invoke onSync, even if issued by a different client. */ my_so.data.
Parameters handlerName A string that identifies the message; also the name of the ActionScript handler to receive the message. The handler name can be only one level deep (that is, it can’t be of the form parent/child) and is relative to the shared object. NO T E Do not use a reserved term for a handler name. For example, myRemote_so.send("close") will fail. p1, ...,pN Optional parameters that can be of any type.
SharedObject.setFps() Availability ■ Flash Player 6. ■ Flash Communication Server MX 1.0. Usage myRemote_so.setFps(updatesPerSecond) Parameters A number that specifies how often a client’s changes to a remote shared object are sent to the server. The default value is the frame rate of the SWF file. updatesPerSecond ■ To send changes immediately and then stop sending changes, pass 0 for updatesPerSecond. ■ To reset updatesPerSecond to its default value, pass a value less than 0.
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. This document discusses the System.showSettings() method and the System.useCodepage property, which are relevant to media applications. For more information on the System class, see the System class entry in the ActionScript 2.0 Language Reference. System.
Description Method; displays the specified Flash Player Settings panel, which lets users do any of the following: ■ Allow or deny access to their camera and microphone ■ Specify settings for local disk space available for shared objects ■ Select a default camera and microphone ■ Specify microphone gain and echo suppression settings For example, if your application requires the use of a camera, you can inform users that they must select Allow in the Privacy dialog box, and then issue a System.
Video class Availability ■ Flash Player 6. ■ Flash Media Server (not required). NO T E In Flash Player 7 and later, Flash Video (FLV) files can be played without the use of Flash Media Server. In Flash Player 8, you can use the On2 VP6 codec and an alpha channel. For more information, see the Video class entry in ActionScript 2.0 Language Reference. The Video class lets you display live or recorded streaming video on the Stage without embedding it in your SWF file.
A Video object can be used like a movie clip. As with other objects you place on the Stage, you can control various properties of Video objects. For example, you can move the Video object around on the Stage by using its _x and _y properties; you can change its size using its _height and _width properties, and so on. To display the video stream, first place a Video object on the Stage. Then use to attach the video stream to the Video object. Video.attachVideo() To place a Video object on the Stage: 1.
Video.attachVideo() Availability ■ Flash Player 6. ■ Flash Media Server (not required). Usage public attachVideo(source:Object) : Void Parameters source A NetStream or Camera object that is playing video or MP3 audio data or capturing video data, respectively. 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 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.flv". */ 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.
Example The following example pauses and clears the image video1.flv that is playing in a Video object (called my_video) when the user clicks the pause_btn instance: var pause_btn:Button; 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"); pause_btn.onRelease = function() { my_ns.pause(); my_video.clear(); }; See also Video.
If a mode greater than 2 is selected for video when you are using the Sorenson codec, the Sorenson decoder defaults to mode 2 internally. The deblocking filter has an effect on overall playback performance, and it is usually not necessary for high-bandwidth video. If your system is not powerful enough, you might experience difficulties playing back video with this filter enabled. Example The following example plays video1.
Description Property (read-only); an integer specifying the height of the video stream, in pixels. This value is the same as the Camera.height property of the Camera object that is capturing (or previously captured) the video stream. You may want to use this property, for example, to ensure that the user is seeing the video at the same size at which it was captured, regardless of the actual size of the Video object on the Stage.
Description Property; a Boolean value that specifies whether the video should be smoothed (interpolated) when it is scaled. For smoothing to work, Flash Player must be in high-quality mode. The default value is false (no smoothing). Example The following example uses a button (called smoothing_btn) to toggle the smoothing property that is applied to the video my_video when it plays in a SWF file. Create a button called smoothing_btn and add the following ActionScript to your FLA or AS file: this.
Video.width Availability ■ Flash Player 6. ■ Flash Media Server (not required). Usage public width : Number [read-only] Description Property (read-only); an integer specifying the width of the video stream, in pixels. This value is the same as the Camera.width property of the Camera object that is capturing (or previously captured) the video stream.
Client-Side ActionScript Language Reference
APPENDIX A A Client-Side Information Objects The Camera, Microphone, LocalConnection, NetConnection, NetStream, and SharedObject objects provide an onStatus event handler that uses an information object for providing information, status, or error messages. To respond to this event handler, you must create a function to process the information object, and you must know the format and contents of the information object returned.
// Attempt to open connection. nConn = new NetConnection(); nConn.connect("rtmp://myServer.myDomain.com/myRTMPapp"); The following tables show the default properties of each information object and the circumstances under which onStatus is invoked with each information object.
Camera information objects The following messages notify you when the user has changed access to a camera—by muting it, resizing it, or shutting it down: Code property Level property Meaning Camera.Muted Status The user denied access to a camera. Camera.Unmuted Status The user allowed access to a camera.
NetConnection information objects The following events notify you when certain NetConnection activities occur: Code property Level property Meaning NetConnection.Call.Failed Error The NetConnection.call () method was not able to invoke the server-side method or command.* NetConnection.Connect.AppShutdown Error The application has been shut down (for example, if the application is out of memory resources and must be shut down to prevent the server from crashing) or the server has been shut down.
Code property Level property Meaning NetStream.Buffer.Empty Status Data is not being received quickly enough to fill the buffer. Data flow is interrupted until the buffer refills, at which time a NetStream.Buffer.Full message is sent and the stream begins playing again. NetStream.Buffer.Full Status The buffer is full and the stream begins playing. NetStream.
Code property Level property Meaning NetStream.Play.StreamNotFound Error The client tried to play a live or recorded stream that does not exist. NetStream.Play.Switch Status The subscriber is switching from one stream to another in a playlist.**** NetStream.Play.UnpublishNotify Status Publishing has stopped; this message is sent to all subscribers. NetStream.Publish.BadName Error The client tried to publish a stream that is already being published by someone else. NetStream.Publish.
Code property Level property Meaning NetStream.Unpause.Notify Status The subscriber has resumed playback. NetStream.Unpublish.Success Status Publishing has stopped. * This information object also has a description property, which is a string that provides a more specific reason for the failure. † This information object also has a details property, which is a string that provides the name of the stream currently playing on the NetStream.
SharedObject information objects The following messages notify you when certain SharedObject activities occur: Code property Level property Meaning SharedObject.BadPersistence Error The persistence parameter passed to SharedObject.getRemote() is different from the one used when the shared object was created. SharedObject.Flush.Failed Error A SharedObject.