MACROMEDIA FLASH MEDIA SERVER 2-CLIENT-SIDE ACTIONSCRIPT LANGUAGE REFERENCE FOR FLASH MEDIA SERVER 2 Reference

Client-side actionscript language reference for flash media server 2

Advertisement

Quick Links

Client-Side ActionScript Language
Reference for Flash Media Server 2

Advertisement

Table of Contents
loading

Summary of Contents for MACROMEDIA FLASH MEDIA SERVER 2-CLIENT-SIDE ACTIONSCRIPT LANGUAGE REFERENCE FOR FLASH MEDIA SERVER 2

  • Page 1 Client-Side ActionScript Language Reference for Flash Media Server 2...
  • Page 2 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.
  • Page 3: Table Of Contents

    Contents Chapter 1: Client-Side ActionScript Language Reference..5 ActionScript classes ..........5 ActionScript elements.
  • Page 4 Contents...
  • Page 5: Chapter 1: Client-Side Actionscript Language Reference

    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.
  • Page 6: Actionscript Elements

    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.
  • Page 7 ActionScript element See entry deblocking Video.deblocking flush SharedObject.flush() Camera.fps gain Microphone.gain 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.motionLevel motionTimeOut Camera.motionTimeOut muted Camera.muted Microphone.muted name Camera.name Microphone.name...
  • Page 8: Camera Class

    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.setQuality() setRate Microphone.setRate() setSilenceLevel Microphone.setSilenceLevel() setUseEchoSuppression Microphone.setUseEchoSuppression() showSettings System.showSettings() silenceLevel Microphone.silenceLevel silenceTimeout Microphone.silenceTimeout...
  • Page 9 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.
  • Page 10 Property summary for the Camera class Property (read-only) Description A numeric value from 0 to 100 that specifies the amount of Camera.activityLevel motion the camera is detecting. The maximum amount of bandwidth the current outgoing Camera.bandwidth video feed can use, in bytes. The rate at which the camera is capturing data, in frames per Camera.currentFps second.
  • Page 11 Event handler summary for the Camera class Method Description Invoked when the camera starts or stops detecting motion. Camera.onActivity Invoked when the user allows or denies access to the camera. Camera.onStatus Constructor for the Camera class Camera.get() Camera.activityLevel Availability Flash Player 6. Flash Media Server (not required).
  • Page 12 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.
  • Page 13 Flash Player MovieClip.getNextHighestDepth() 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 method. MovieClip.getNextHighestDepth() See also Camera.setQuality()
  • Page 14 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.
  • Page 15 See also Camera.currentFps Camera.setMode() Camera.get() Availability Flash Player 6. Flash Media Server (not required). Usage public static get([index:Number]) : Camera 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 index determined from the array returned by .
  • Page 16 Unlike objects that you create using the constructor, multiple calls to Camera.get() reference the same camera driver. Thus, if your script contains the lines , both reference the same cam1 = Camera.get() cam2 = Camera.get() cam1 cam2 (default) camera driver. In general, you shouldn’t pass a value for ;...
  • Page 17 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 is called.
  • Page 18 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.
  • Page 19 = my_cam.index+". "+my_cam.name; method used in this example requires Flash Player MovieClip.getNextHighestDepth() 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 method.
  • Page 20 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).
  • Page 21 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 . Acceptable values range from 0 to 100. The default value is 50. Camera.onActivity(true) Video can be displayed regardless of the value of the property.
  • Page 22 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"...
  • Page 23 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 property using a NumericStepper instance. Create a new video instance by motionTimeout selecting New Video from the Library options menu.
  • Page 24 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 ( ) or allowed access ( ) in the Flash Player Privacy dialog box. When this true false value changes,...
  • Page 25 = my_cam.name; method used in this example requires Flash Player MovieClip.getNextHighestDepth() 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 method.
  • Page 26 Camera.names Availability Flash Player 6. Flash Media Server (not required). Usage public static names : Array [read-only] The correct syntax is . To assign the return value to a variable, use syntax Camera.names like . To determine the name of the current camera, var cam_array:Array = Camera.names , where is the variable to which you assigned the results...
  • Page 27 Camera.onActivity Availability Flash Player 6. Flash Media Server (not required). Usage public onActivity = function(activity:Boolean) {} Parameters A Boolean value set to when the camera starts detecting motion, activity true 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 value.
  • Page 28 Camera.onStatus Availability Flash Player 6. Flash Media Server. Usage public onStatus = function(infoObject:Object) {} Parameters A parameter defined according to the status message. For more information infoObject about this parameter, see “Camera information objects” on page 151. Returns Nothing. Description Event handler;...
  • Page 29 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");...
  • Page 30 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 .
  • Page 31 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;...
  • Page 32 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 lets you see more precisely how the video will compressLocalStream true appear to users when they view it in real time.
  • Page 33 Parameters The requested capture width, in pixels. The default value is 160. width The requested capture height, in pixels. The default value is 120. height The requested rate at which the camera should capture data, in frames per second. The default value is 15.
  • Page 34 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 .
  • Page 35 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) Video can be displayed regardless of the value of the parameter.
  • Page 36 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();...
  • Page 37 An integer that specifies the required level of picture quality, as determined by the quality 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 .
  • Page 38: Microphone Class

    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.
  • Page 39 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.
  • Page 40 Property (read-only) Description A Boolean value that specifies whether the user has Microphone.muted allowed or denied access to the microphone. The name of the current sound capture device, as Microphone.name returned by the sound capture hardware. Class property: an array of strings reflecting the names Microphone.names of all available sound capture devices, including sound capture cards and microphones.
  • Page 41 Flash Player MovieClip.getNextHighestDepth() 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 method.
  • Page 42 Flash Player MovieClip.getNextHighestDepth() 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 method.
  • Page 43 Microphone.get() Availability Flash Player 6. Flash Media Server (not required). Usage public static get([index:Number]) : Microphone The correct syntax is . To assign the Microphone object to a variable, Microphone.get() use syntax like var active_mic:Microphone Microphone.get() Parameters An optional zero-based integer that specifies which microphone to get, as determined index from the array returned by .
  • Page 44 Flash Player MovieClip.getNextHighestDepth() 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 method.
  • Page 45 Flash Player MovieClip.getNextHighestDepth() 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 method.
  • Page 46 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 ( ) or allowed access ( ). When this value changes, true false is invoked.
  • Page 47 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+"...
  • Page 48 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...
  • Page 49 Example The following example displays in the Output panel when the microphone true false 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). Usage public onStatus = function(infoObject:Object) {} Parameters...
  • Page 50 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 property is set to , and this event Microphone.muted false handler is invoked with an information object whose...
  • Page 51 Flash Player MovieClip.getNextHighestDepth() 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 method. MovieClip.getNextHighestDepth() See also Microphone.get()
  • Page 52 Parameters An integer that specifies the amount by which the microphone should boost the gain 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. Returns Nothing.
  • Page 53 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 variable) if it is one of the following values: 5, 8, 11, 22, or 44. If it userRate is not, the value is rounded to the nearest acceptable value that the sound capture device supports.
  • Page 54 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 is never invoked.
  • Page 55 = "Activity level: (inactive)"; method used in this example requires Flash Player MovieClip.getNextHighestDepth() 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 method.
  • Page 56 Microphone.setUseEchoSuppression() Availability Flash Player 6. Flash Media Server (not required). Usage public setUseEchoSuppression(suppress : Boolean) : Void Parameters A Boolean value indicating whether echo suppression should be used ( ) or suppress true not ( false Returns Nothing. Description Method; specifies whether to use the echo suppression feature of the audio codec. The default value is unless the user has selected Reduce Echo in the Flash Player Microphone false...
  • Page 57 Example The following example turns on echo suppression if the user selects a CheckBox instance called . The ProgressBar instance called useEchoSuppression_ch 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);...
  • Page 58 = "Activity level: (inactive)"; method used in this example requires Flash Player MovieClip.getNextHighestDepth() 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 method.
  • Page 59 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.
  • Page 60 = "Activity level: (inactive)"; method used in this example requires Flash Player MovieClip.getNextHighestDepth() 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 method.
  • Page 61: Movieclip Class

    Flash Player MovieClip.getNextHighestDepth() 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 method.
  • Page 62 MovieClip.attachAudio() Availability Flash Player 6. Flash Media Server (not required). Usage public attachAudio(source : Object) : Void Parameters The object containing the audio to play. Valid values are a Microphone object, a source NetStream object (requires Flash Media Server), and (stops playing the audio).
  • Page 63 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 . Dynamically load the FLV video at runtime. Use the my_video method to attach the audio from the FLV file to a movie clip on the Stage.
  • Page 64: Netconnection Class

    Flash Player MovieClip.getNextHighestDepth() 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 method. MovieClip.getNextHighestDepth()
  • Page 65 Method summary for the NetConnection class Method Description Invokes a command or method on the server. NetConnection.call() Closes the connection with the server. NetConnection.close() Connects to an application on the Flash Media Server. NetConnection.connect() Property summary for the NetConnection class Property (read-only) Description Read-only;...
  • Page 66 Server or to an application server. After creating the NetConnection object, use to make the actual connection. NetConnection.connect() For information on using Flash with an application server, see http://www.macromedia.com/ go/flashmediaserver_desdev_en. Example The following function uses the NetConnection constructor to create a new...
  • Page 67 This method is also used when your application connects to an application server. For information on using Flash with an application server, see http:// www.macromedia.com/go/flashmediaserver_desdev_en. Example The following function checks for a message, sends it, then clears the local string.
  • Page 68 Description Method; closes the connection with the server and invokes with a NetConnection.onStatus property of . For more information, see code NetConnection.Connect.Close 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 .) If you want to reconnect, you must recreate the NetStream.close()
  • Page 69 . (To determine if the true false connection was successfully completed, use NetConnection.onStatus Description Method; connects to an application on the Flash Media Server. This method can also be used to communicate with an application server. For information, see http:// www.macromedia.com/go/flashmediaserver_desdev_en. NetConnection class...
  • Page 70 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.
  • Page 71 Because of network and thread timing issues, it is better to place a NetConnection.onStatus handler in a script before a method. Otherwise, the connection NetConnection.connect() might complete before the script executes the handler initialization. Also, all onStatus security checks are made within the method, and notifications NetConnection.connect() will be lost if the...
  • Page 72 In another case, you may have an application named that records and plays lectureSeries 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");...
  • Page 73 The following example connects over the RTMP protocol to the default instance of the application located on the host of the server using the default funAndGames real macromedia port: my_nc = new NetConnection(); my_nc.connect("rtmp://real.macromedia.com/funAndGames"); The following example connects over the RTMPT protocol to the application...
  • Page 74 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);...
  • Page 75 NetConnection.onStatus Availability Flash Player 6. Flash Communication Server MX 1.0. Usage my_nc.onStatus = function(infoObject) { // your code here Parameters A parameter defined according to the status message. For more information infoObject about this parameter, see “NetConnection information objects” on page 152.
  • Page 76: Netstream Class

    Usage my_nc.uri Description Property (read-only); a string representing the target URI that was passed in with . If hasn’t yet been called for NetConnection.connect() NetConnection.connect() my_nc this property is undefined. See also NetConnection.connect() NetStream class Availability Flash Player 6. Flash Communication Server MX 1.0. In Flash Player 7 and later, you can use this method to play FLV files without Flash Media Server.
  • Page 77 to give this stream a unique name and NetStream.publish(publishName:String) 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;...
  • Page 78 Method summary for the NetStream class Method Description Publisher method; specifies whether audio should be sent NetStream.attachAudio() over the stream. Publisher method; starts transmitting video or a snapshot NetStream.attachVideo() from the specified source. Stops publishing or playing all data on the stream and NetStream.close() makes the stream available for another use.
  • Page 79 Property summary for the NetStream class Property (read-only) Description The number of seconds of data currently in the buffer. NetStream.bufferLength The number of seconds assigned to the buffer by NetStream.bufferTime NetStream.setBufferTime() The number of frames per second being sent or received on NetStream.currentFps the publishing or subscribing stream.
  • Page 80 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 , an implicit NetStream.play()
  • Page 81 NetStream.attachAudio() Availability Flash Player 6. Flash Communication Server MX 1.0. Usage public attachAudio(source:Microphone) : Void Parameters The source of the audio to be transmitted. Valid values are a Microphone object source null Returns Nothing. Description Method; specifies whether audio should be sent over the stream (from a Microphone object passed as ) or not ( passed as...
  • Page 82 NetStream.attachVideo() Availability Flash Player 6. Flash Communication Server MX 1.0. Usage public attachVideo(source : Camera [, snapShotMilliseconds : Number]) Parameters The source of the video transmission. Valid values are a Camera object (which starts source capturing video) and . If you pass , Flash stops capturing video, and any additional null null...
  • Page 83 After attaching the video source, you must call to actually begin NetStream.publish() transmitting. Subscribers who want to display the video must call the NetStream.play() methods to display the video on the Stage. Video.attachVideo() You can use to send a single snapshot (by providing a value of 0) or snapShotMilliseconds 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.
  • Page 84 Example The following function publishes a stream on a NetConnection named containing the my_nc 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.
  • Page 85 "+my_ns.bufferTime+"\t"+"Buffer:"+bufferPct+"%"; output_str += "</textformat>"; buffer_txt.htmlText = output_str; 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 method, which is used in this example.
  • Page 86 "+my_ns.bufferTime+"\t"+"Buffer:"+bufferPct+"%"; output_str += "</textformat>"; buffer_txt.htmlText = output_str; 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 method, which is used in this example.
  • Page 87 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 from a publishing stream, or NetStream.play()
  • Page 88 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.
  • Page 89: Property Description

    Example The following example displays a string (inside a text field named connectionQuality_str indicating the connection quality over the NetStream object named , according to the my_ns value of the property. liveDelay if (my_ns.liveDelay < .5) { connectionQuality_str.text = "Good"; } else if (my_ns.liveDelay <...
  • Page 90 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. The following are two types of cue points that can be embedded in an FLV file: A navigation cue point specifies a keyframe within the FLV file;...
  • Page 91 Example The code in this example starts by creating new NetConnection and NetStream objects. Then it defines the handler for the NetStream object. The handler cycles through each onCuePoint named property in the object and prints the property's name and value. When it infoObject finds the property named , it cycles through each parameter name in the list and...
  • Page 92 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 =...
  • Page 93 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.
  • Page 94 NetStream.onPlayStatus Availability Flash Player 6. Flash Media Server 2. Usage public onPlayStatus = function(infoObject:Object) {} Parameters An object containing an error or status message. For more information about infoObject this parameter, see “NetStream information objects” on page 153. Returns Nothing. Description Event handler;...
  • Page 95 NetStream.onStatus Availability Flash Player 6. Flash Communication Server MX 1.0. Usage public onStatus = function(infoObject:Object) {} Parameters A parameter defined according to the status or error message. For more infoObject information about this parameter, see “NetStream information objects” on page 153.
  • Page 96 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 ( ) or resume play flag true ). If you omit this parameter, acts as a toggle: the first time it is false NetStream.pause()
  • Page 97 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);...
  • Page 98 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 , a recorded file name NetStream.publish() name for playback, or .
  • Page 99 An optional numeric parameter that specifies the duration of the playback, in seconds. The default value for 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 , Flash plays the single frame that is seconds from the...
  • Page 100 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: Flash Player behavior start (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.
  • Page 101 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();...
  • Page 102 NetStream.publish() Availability Flash Player 6. Flash Communication Server MX 1.0. Usage public publish(name : String [, howToPublish : String] ) : Void Parameters A string value that identifies the stream. If you pass , the publish operation name false stops. Subscribers to this stream must pass this same name when they call .
  • Page 103 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 To enable someone to play it back, you need only open a stream for the “allAboutMe.”...
  • Page 104 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");...
  • Page 105 If the specified stream contains only audio data, passing a value of to this method stops false from further incrementing. NetStream.time 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 receive...
  • Page 106 If you pass the 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;...
  • Page 107 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 flag on the server.
  • Page 108 Parameters A string value that identifies the message; also the name of the ActionScript handlerName handler to receive the message. The handler name can be only one level deep (that is, it can’t be of the form ) and is relative to the stream object. parent/child Do not use a reserved term for a handler name.
  • Page 109 NetStream.setBufferTime() Availability Flash Player 6. Flash Communication Server MX 1.0. Usage public setBufferTime(bufferTime : Number) : Void Parameters The number of seconds to be buffered before Flash stops sending data (on a bufferTime publishing stream) or begins displaying data (on a subscribing stream). The default value is 9. The default value for Flash Media Server parameter is different than the bufferTime...
  • Page 110 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;...
  • Page 111 my_ns.attachVideo(active_cam); // After 10 seconds, my_ns.time = 20. The following example shows how is reset to 0 when you stop publishing a NetStream.time 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.
  • Page 112: Sharedobject Class

    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”...
  • Page 113 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");...
  • Page 114 Data design and management Data associated with shared objects are stored in attributes of the object’s properties; data 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";...
  • Page 115 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.
  • Page 116 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.
  • Page 117 Method Description Broadcasts a message to all clients connected to the remote SharedObject.send() shared object, including the client that sent the message. Specifies the number of times per second that a client’s SharedObject.setFps() changes to a shared object are sent to the server. Property summary for the SharedObject class Property (read-only) Description...
  • Page 118 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 is still active, but properties my_so my_so data 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.
  • Page 119 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.
  • Page 120 Before attempting to work with a remote shared object, you should first check for a return value of , indicating a successful connection, and then wait until you receive a result from true the function you have assigned to . If you fail to do so, any changes SharedObject.onSync you make to the object locally—before is invoked—may be lost.
  • Page 121 All attributes of a shared object’s property are available to all clients connected to the data 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...
  • Page 122 SharedObject.flush() Availability Flash Player 6. Flash Media Server (not required). Usage myLocalOrRemote_so.flush([minimumDiskSpace]) Parameters An optional integer specifying the number of bytes that must be minimumDiskSpace allotted for this object. The default value is 0. Returns A Boolean value of , or a string value of as described in the true false...
  • Page 123 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 . If Flash asks the user minimumDiskSpace 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).
  • Page 124 For a remote shared object, calling in the client-side ActionScript SharedObject.flush() 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.
  • Page 125 An optional string parameter that specifies the full or partial path to the SWF localPath 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 secure...
  • Page 126 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() 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 is specified.
  • Page 127 // 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.
  • Page 128 An optional value that specifies whether the attributes of the shared object’s persistence property are persistent locally, remotely, or both, and that may specify where the shared data object will be stored locally. Acceptable values are as follows: (default) or specifies that the shared object is not persistent on the client or null false...
  • Page 129 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.
  • Page 130 For example, if you specify "/a/b/" for the SWF file named above and also for a SWF file whose full path is www.macromedia.com/a/b/foo2.swf, each SWF file can read shared objects created by the other SWF file. When specifying , do not include a domain name.
  • Page 131 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.
  • Page 132 SharedObject.onStatus Availability Flash Player 6. Flash Media Server (not required). Usage public onStatus = function(infoObject) {} Parameters A parameter defined according to the status message. For more information infoObject about this parameter, see “SharedObject information objects” on page 156. Returns Nothing.
  • Page 133 Parameters An array of objects; each object contains properties that describe the changed objArray 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 , and later invoked whenever any client SharedObject.connect() changes the attributes of the...
  • Page 134 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;...
  • Page 135 Parameters A string that identifies the message; also the name of the ActionScript handler handlerName to receive the message. The handler name can be only one level deep (that is, it can’t be of the form ) and is relative to the shared object. parent/child Do not use a reserved term for a handler name.
  • Page 136 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 updatesPerSecond object are sent to the server. The default value is the frame rate of the SWF file. To send changes immediately and then stop sending changes, pass 0 for updatesPerSecond To reset...
  • Page 137: System Class

    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 method System.showSettings() and the property, which are relevant to media applications.
  • Page 138 ActionScript code, your media application might not work properly. A value of true causes Macromedia Flash Player to handle text based on the end user’s code page, as in early versions of the player. Flash Player, however, will still send UTF-8 encoded text to Flash Media Server, and all text received from the server will be UTF-8 encoded as well.
  • Page 139: Video Class

    Video class Availability Flash Player 6. Flash Media Server (not required). 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.
  • Page 140 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 properties;...
  • Page 141 Video.attachVideo() Availability Flash Player 6. Flash Media Server (not required). Usage public attachVideo(source:Object) : Void Parameters A NetStream or Camera object that is playing video or MP3 audio data or source capturing video data, respectively. To drop the connection to the Video object, pass null source Returns...
  • Page 142 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");...
  • Page 143 Example The following example pauses and clears the image video1.flv that is playing in a Video object (called ) when the user clicks the instance: my_video pause_btn var pause_btn:Button; var my_video:Video; // my_video is a Video object on the Stage. var my_nc:NetConnection = new NetConnection();...
  • Page 144 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.
  • Page 145 Description Property (read-only); an integer specifying the height of the video stream, in pixels. This value is the same as the property of the Camera object that is capturing (or Camera.height 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.
  • Page 146 = "smoothing = "+my_video.smoothing; method used in this example requires Flash Player MovieClip.getNextHighestDepth() 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 method.
  • Page 147 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 property of the Camera object that is capturing (or Camera.width previously captured) the video stream.
  • Page 148 Client-Side ActionScript Language Reference...
  • Page 149: Appendix A: Client-Side Information Objects

    In addition to the specific handlers provided for the objects listed above, onStatus Macromedia Flash also provides a super function called . If System.onStatus onStatus invoked for a particular object with a level property of...
  • Page 150 For information on using Flash with an application server, see Using Flash Remoting which you can download from the Macromedia website. For objects that do not require Flash Media Server (Camera, Microphone,...
  • Page 151: Camera Information Objects

    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.
  • Page 152: Netconnection Information Objects

    NetConnection information objects The following events notify you when certain NetConnection activities occur: Code property Level property Meaning NetConnection.Call.Failed Error 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...
  • Page 153: Netstream Information Objects

    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...
  • Page 154 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.
  • Page 155 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 property, which is a string that provides a description more specific reason for the failure. † This information object also has a property, which is a string that provides the details name of the stream currently playing on the NetStream.
  • Page 156: Sharedobject Information Objects

    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() different from the one used when the shared object was created. SharedObject.Flush.Failed Error SharedObject.flush() method that returned "pending"...

This manual is also suitable for:

Media server 2

Table of Contents