Summary of Contents for MACROMEDIA FLASH COMMUNICATION SERVER MX-SERVER-SIDE COMMUNICATION ACTIONSCRIPT DICTIONARY
Page 1
Server-Side Communication ActionScript Dictionary Macromedia Flash Communication Server MX ™ ™ macromedia ®...
Page 2
Shockwave, Shockwave Remote, Shockwave Internet Studio, Showcase, Tools to Power Your Ideas, Universal Media, Virtuoso, Web Design 101, Whirlwind and Xtra are trademarks of Macromedia, Inc. and may be registered in the United States or in other jurisdictions including internationally. Other product names, logos, designs, titles, words or phrases mentioned within this publication may be trademarks, servicemarks, or tradenames of Macromedia, Inc.
Server-Side Communication ActionScript Server-Side Communication ActionScript is a scripting language on the server that lets you develop efficient and flexible client-server Macromedia Flash Communication Server MX applications. For example, you can use server-side ActionScript to control login procedures, control events in connected Flash movies, determine what users see in their Flash movies, and communicate with other servers.
To install and test the server-side ActionScript file, do the following: Locate the flashcom application directory. During installation, you can choose either a Developer Install or a Production Install of the product. If you choose Developer Install, you can run the samples and test your applications from the \flashcom\applications directory under the directory you specify.
Naming applications Flash Communication Server application names must follow the Uniform Resource Identifier (URI) RFC 2396 convention (see http://www.w3.org/Addressing/). This convention supports a hierarchical naming system where a forward slash (/) separates the elements in the hierarchy. The first element specifies the application name. The element following the application name specifies the application instance name.
__resolve Client.__resolve resyncDepth SharedObject.resyncDepth send SharedObject.send, Stream.send setBandwidthLimit Client.setBandwidthLimit setBufferTime Stream.setBufferTime setInterval setInterval setProperty SharedObject.setProperty SharedObject SharedObject (object) size SharedObject.size server Application.server Stream Stream (object) trace trace unlock SharedObject.unlock NetConnection.uri version SharedObject.version writeAccess Client.writeAccess Application (object) The Application object contains information about a Flash Communication Server application instance that lasts until the application instance is unloaded.
Method summary for the Application object Method Description Accepts a connection to an application from a client. Application.acceptConnection Application.clearSharedObjects Clears all shared objects associated with the current instance. Application.clearStreams Clears all stream objects associated with the current instance. Disconnects a client from the server. Application.disconnect Application.registerClass Registers or unregisters a constructor that is called during object...
Description Method; accepts the connection call from a client to the server. The application.onConnect event handler is invoked on the server side to notify a script when NetConnection.connect called from the client side. You can use the method inside an application.acceptConnection event handler to accept a connection from a client.
The following are possible values for the parameter: soPath • clears all local and persistent shared objects associated with the instance. • clears the shared object ; if bar is a directory name, no shared objects are /foo/bar /foo/bar deleted. •...
The following are possible values for the parameter: streamPath • clears all recorded streams associated with the instance. • clears recorded streams /foo/bar; if bar is a directory name, no streams are deleted. /foo/bar • clears all streams stored in the instance directory /foo/bar. The bar directory is /foo/bar/* also deleted if no streams are in use within this name space.
Example This example uses a loop to iterate through each member of the array application.clients and calls the method on each client: serverUpdate for (i = 0; i < application.clients.length; i++){ application.clients[i].call("serverUpdate"); Application.disconnect Availability Flash Communication Server MX. Usage application.disconnect(clientObj) Parameters The client to disconnect.
Example The following example checks the property against a specific string before it executes some name code: if (application.name == "videomail/work"){ // insert code here Application.onAppStart Availability Flash Communication Server MX. Usage application.onAppStart = function (info){ // insert code here Parameters None.
Description Event handler; invoked when the application is about to be unloaded by the server. You can define a function that executes when the event handler is invoked. If the function returns true the application unloads. If the function returns , the application doesn’t unload.
Page 17
Optional parameters passed to the method. These p1 ..., pN application.onConnect parameters are passed from the client-side method when a client NetConnection.connect connects to the application. Returns The value you provide. If you return a Boolean value of , the server accepts the connection; if true the value is , the server rejects the connection.
Description Event handler; invoked on the server side when is called from the NetConnection.connect client side and a client attempts to connect to an application instance. You can define a function for the event handler. If you don’t define a function, connections are application.onConnect accepted by default.
Usage Example application.onDisconnect = function (clientObj){ The following example defines a function that sends a trace statement whenever the // insert code here application.onStatus Parameters A client disconnecting from the application. clientObj Returns The server ignores any return value. Description Event handler;...
If you register a class that has its prototype set to another class, you must set the prototype constructor back to the original class after setting the prototype. The second example below illustrates this point. Example This example defines a constructor function with properties and methods.
Parameters The name of a method. All requests to execute for this application methodName methodName instance are forwarded to the object. proxyConnection A Client or NetConnection object. All requests to execute the remote proxyConnection method specified by are sent to the Client or NetConnection object that is specified methodName in the parameter.
Returns Nothing. Description Method; rejects the connection call from a client to the server. The application.onConnect event handler notifies a script when a new client is connecting. In the function assigned to , you can either accept or reject the connection. You can also define a application.onConnect function for that calls an application server for authentication.
clearInterval Availability Flash Communication Server MX. Usage clearInterval(intervalID) Parameters A unique ID returned by a previous call to the method. intervalID setInterval Returns Nothing. Description Method (global); cancels a time-out that was set with a call to the method. setInterval Example The following example creates a function named and passes it to the...
Page 24
// a good naming convention is to start all class method // names with the name of the class, followed by an underscore You can also add properties to , as shown in the following example: prototype Client.prototype.company = "Macromedia"; Server-Side Communication ActionScript...
The methods are available to any instance, so within , which is passed a application.onConnect argument, you can write the following code: clientObj application.onConnect(clientObj){ var clientID = clientObj.createUniqueID(); var clientWritePerm = clientObj.getWritePermission(); Method summary for the Client object Method Description Executes a method on the Flash client asynchronously and returns the value Client.call from the Flash client to the server.
Example The following example checks the property against the string and executes different agent "WIN" code depending on whether they match. This code is written inside an function. onConnect function onConnect(newClient, name){ if (newClient.agent.indexOf("WIN") > -1){ trace ("Window user"); } else { trace ("non Window user.agent is"...
The following server-side script uses the method inside the Client.call handler to call the method that was defined on the client side. application.onConnect random The server-side script also defines a function called , which is used in the randHander method as the parameter.
method can then be called from on the Flash client side, as shown NetConnection.call in the following example: nc = new NetConnection(); nc.connect("rtmp://myServer/myApp"); nc.call("sum", new result.sum(), 20, 50); function result.sum(){ this.onResult = function (retVal){ output += "sum is " + retVal; this.onStatus = function(errorVal){ output += errorVal.code + "...
Returns An integer indicating bytes per second. Description Method; returns the maximum bandwidth that the client or the server can use for this connection. Use the parameter to get the value for each direction of the connection. iDirection The value returned indicates bytes per second and can be changed with .
By default, all clients have full read access, and the property is set to slash ( ). To give readAccess a client read access, specify a list of access levels (in URI format), delimited by semicolons. Any files or directories within a specified URI are also considered accessible. For example, if myMedia is specified as an access level, then any files or directories in the myMedia directory are also accessible (for example, myMedia/mp3s).
Parameters The name of an undefined property. propName Returns The value of the undefined property, which is specified by the parameter. propName Description Method; provides values for undefined properties. When an undefined property of a Client object is referenced by server-side ActionScript code, that object is checked for a method.
Client.writeAccess Availability Flash Communication Server MX. Usage Client.writeAccess Description Property; provides write-access rights to application resources (shared objects, streams, and so on) for this client. To give a client write access to directories containing application resources, list directories in a string delimited by semicolons. By default, all clients have full write access, and property is set to slash ( ).
Flash Communication Servers or application instances. You can use Macromedia Flash Remoting with the Flash Communication Server to communicate with application servers such as Macromedia ColdFusion MX, Macromedia JRun, Microsoft .NET, and J2EE servers using Action Message Format (AMF) over HTTP.
Method summary for the NetConnection object Method Description NetConnection.addHeader Adds a context header. NetConnection.call Invokes a method or operation on a remote server. Closes a server connection. NetConnection.close NetConnection.connect Establishes connection to a server. Property summary for the NetConnection object Property Description A Boolean value indicating whether a connection has been made.
Parameters A string that identifies the header and the ActionScript object data associated with it. name A Boolean value; indicates that the server must understand and process mustUnderstand true this header before it handles any of the following headers or messages. Any ActionScript object.
Description Method; invokes a command or method on a Flash Communication Server or an application server to which the application instance is connected. The method on the NetConnection.call server works the same way as the method on the client: it invokes a NetConnection.call command on a remote server.
Example The following code closes the NetConnection instance myNetConn myNetConn.close(); NetConnection.connect Availability Flash Communication Server MX. Usage myNetConnection.connect(URI, [p1, ..., pN]) Parameters A URI to connect to. Optional parameters that can be of any ActionScript type, including references to p1, ..., pN other ActionScript objects.
Usage myNetConnection.isConnected Description Property (read-only); a Boolean value that indicates whether a connection has been made. It is set if there is a connection to the server. It’s a good idea to check this property value in the true callback function. This property is always true for AMF connections to application onStatus servers.
Example This example defines a function for the handler that outputs messages to indicate onStatus whether the NetConnection was successful: nc = new NetConnection(); nc.onStatus = function(info){ if (info.code == "NetConnection.Connect.Success") { _root.gotoAndStop(2); } else { if (! nc.isConnected){ _root.gotoAndStop(1); NetConnection.uri Availability Flash Communication Server MX.
Description Method (global); continually calls a function or method at a specified time interval until the method is called. This method allows a server-side script to run a generic clearInterval routine. The method returns a unique ID that you can pass to the setInterval clearInterval method to stop the routine.
Page 41
Every shared object is identified by a unique name and contains a list of name-value pairs, called properties, just like any other ActionScript object. A name must be a unique string and a value can be any ActionScript data type. (For more information about data types, see Using Flash MX.) All shared objects have a data property.
Method summary for the SharedObject object Method Description SharedObject.clear Deletes all properties of a persistent shared object. SharedObject.close Unsubscribes from a shared object. Causes the server to save the current state of a shared object. SharedObject.flush SharedObject.get Returns a reference to a shared object. SharedObject.getProperty Gets the value of a shared object property.
Parameters None. Returns Returns if successful; otherwise. true false Description Method; deletes all properties and sends a “clear” event to all clients that subscribe to a persistent shared object. The persistent data object is also removed from persistent shared object. You can to detach from a shared object immediately after SharedObject.clear SharedObject.get...
SharedObject.flush Availability Flash Communication Server MX. Usage SharedObject.flush() Parameters None. Returns A Boolean value of if successful, otherwise. true false Description Method; causes the server to save the current state of the shared object instance. The shared object must have been created with the persistence option. Example The following example places a reference to the shared object in the variable...
Page 45
Description Static method; returns a reference to a shared object instance. To perform any operation on a shared object, the server-side script must get a reference to the named shared object using the method. If the object requested is not found, a new instance is created. SharedObject.get There are two types of shared objects, persistent and nonpersistent, and they are in separate name spaces.
Example This example creates a shared object named inside the function . The function onProcessCmd is passed a parameter, , that is assigned to a property in the shared object. function onProcessCmd(cmd){ // insert code here var shObj = SharedObject.get("foo", true); propName = cmd.name;...
SharedObject.getPropertyNames Availability Flash Communication Server MX. Usage mySharedObject.getPropertyNames() Parameters None. Returns An array containing all the property names of a shared object. Description Method; enumerates all the property names for a given shared object. This method returns an array of strings that refer to the current properties. Example This example calls on the...
keyword used in the body of the function is set to the shared object instance returned this SharedObject.get If you don’t want the server to receive a particular broadcast message, do not define this handler. Example The following example defines a handler function called broadcastMsg var mySO = SharedObject.get("userList", false);...
Example This example outputs to the NetConnection Debugger: mySO = SharedObject.get("foo"); trace(mySO.name); SharedObject.onStatus Availability Flash Communication Server MX. Usage SharedObject.onStatus = function(info) { // insert code here Parameters An information object. For more information, see the Appendix, “Client-Side info Information Objects,” in the Client-Side Communication ActionScript Dictionary. Returns Nothing.
Page 50
Local shared objects Code Meaning change A property was changed by a subscriber. delete A property was deleted by a subscriber. The name of a property that has changed or been deleted. name oldValue The old value of a property. This is true for both change and delete messages; on the client, oldValue is not set for delete.
Example The following example creates a function that is invoked whenever a property of the shared object changes: // create a new NetConnection object nc = new NetConnection(); nc.connect("rtmp://server1.xyx.com/myApp"); // create the shared object so = SharedObject.get("MasterUserList", true, nc); // the list parameter is an array of objects containing information // about successfully of unsuccessfully changed properties // from the last time onSync() was called so.onSync = function(list) {...
SharedObject.resyncDepth Availability Flash Communication Server MX. Usage SharedObject.resyncDepth Description Property; an integer that indicates when the deleted properties of a shared object should be permanently deleted. You can use this property in a server-side script to resynchronize shared objects and to control when shared objects are deleted. The default value is infinity. If the current revision number of the shared object minus the revision number of the deleted property is greater than the value of , the property is deleted.
= SharedObject.get("foo", true); myShared.send("doSomething", "this is a test"); The following example is the client-side ActionScript code that defines the method: doSomething connection = new NetConnection(); connection.connect("rtmp://www.macromedia.com/someApp"); var x = SharedObject.getRemote("foo", connection.uri, true); x.connect(connection); x.doSomething = function(str) { // process the str SharedObject.setProperty Availability Flash Communication Server MX.
If you call on the server side, it invokes a change message in the SharedObject.setProperty method on the client side for any Flash Player client that is using the SharedObject.onSync shared object. The parameter on the server side is the same as an attribute of the name data property on the client side.
Usage mySharedObject.unlock() Parameters None. Returns An integer indicating the lock count: 0 or greater if successful, -1 otherwise. For proxied shared objects, this method always returns -1. Description Method; unlocks a shared object instance. This causes the script to relinquish exclusive access to the shared object and lets other clients update the instance.
You can create other Stream properties of any legal ActionScript type, including references to other ActionScript objects, for a particular instance of the Stream object. The properties are available until the stream is removed from the application. For more information about streams, see the NetStream (object) entry in the Client-Side Communication ActionScript Dictionary.
Stream.clear Availability Flash Communication Server MX. Usage Stream.clear() Parameters None. Returns A Boolean value of if the call succeeds, otherwise. true false Description Method; deletes a stream that uses previously recorded by the server. Example This example deletes a recorded stream called .
Example This example gets the stream and assigns it to the variable . It then calls the playStream method from Stream.play playStream function onProcessCmd(cmd){ var playStream = Stream.get("foo"); playStream.play("file1", 0, -1); Stream.length Availability Flash Communication Server MX. Usage Stream.length(name) Parameters Name of a recorded stream.
Usage myStream.onStatus = function([infoObject]) { // Insert code here Parameters An optional parameter defined according to the status message. For details about infoObject this parameter, see the Appendix, “Server-Side Information Objects,” on page 67. Returns Nothing. Description Event handler; invoked every time the status of a Stream object changes. For example, if you play a file in a stream, is invoked.
Page 60
A Boolean value that flushes the playing stream. If , the server maintains a reset reset false playlist, and each call to is appended to the end of the playlist so that the next play Stream.play does not start until the previous play finishes. You can use this technique to create a dynamic playlist.
Example This example illustrates how streams can be chained between servers: application.myRemoteConn = new NetConnection(); application.myRemoteConn.onStatus = function(info){ trace("Connection to remote server status " + info.code + "\n"); // tell all the clients for (var i = 0; i < application.clients.length; i++){ application.clients[i].call("onServerStatus", null, info.code, info.description);...
Parameters This parameter can have the value , or . If the value is , the flag record append false record data file is overwritten if it exists. If the value is , the incoming data is appended to the end append of the existing file.
Description Method; calls a method on all the clients subscribing to a stream. When you call Stream.send the server side, any client publishing to that stream is stopped from publishing. Therefore, the best practice is to create a new stream before calling .
trace Availability Flash Communication Server MX. Usage trace("Hello world"); trace("Value of i = " + i); Returns Nothing. Description Method (global); displays the value of an expression in the Output window. The message is trace also published to the logs/application appname stream, which is available in the Administration Console or in the Communication App inspector.
APPENDIX Server-Side Information Objects The Application, NetConnection, and Stream objects provide an event handler that onStatus 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.
Code Level Meaning Application.Resource.LowMemory Warning The ActionScript engine is low on runtime memory. This provides an opportunity for the application instance to free some resources or take suitable action. If the application instance runs out of memory, it is unloaded and all users are disconnected.
Page 68
Code Level Meaning NetStream.Failed Error An attempt to use a Stream method failed.* NetStream.Unpublish.Success Status An attempt to unpublish was successful. Status Recording was started. NetStream.Record.Start Error An attempt was made to record a read-only NetStream.Record.NoAccess stream. Status Recording was stopped. NetStream.Record.Stop Error An attempt to record a stream failed.
Need help?
Do you have a question about the FLASH COMMUNICATION SERVER MX-SERVER-SIDE COMMUNICATION ACTIONSCRIPT DICTIONARY and is the answer not in the manual?
Questions and answers