MACROMEDIA FLASH COMMUNICATION SERVER MX-SERVER-SIDE COMMUNICATION ACTIONSCRIPT DICTIONARY Manual

Summary of FLASH COMMUNICATION SERVER MX-SERVER-SIDE COMMUNICATION ACTIONSCRIPT DICTIONARY

  • Page 1

    Macromedia ™ ® server-side communication actionscript dictionary macromedia flash ™ communication server mx.

  • Page 2

    Trademarks afterburner, appletace, attain, attain enterprise learning system, attain essentials, attain objects for dreamweaver, authorware, authorware attain, authorware interactive studio, authorware star, authorware synergy, backstage, backstage designer, backstage desktop studio, backstage enter...

  • Page 3

    3 contents server-side communication actionscript . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 using server-side actionscript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 using naming conventions . . . . . . . . . . . . . . . . . . . . . . ...

  • Page 4

    Contents 4 netconnection.Isconnected . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 netconnection.Onstatus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 netconnection.Uri . . . . . . . . . . . . . . . ...

  • Page 5

    Server-side communication actionscript 5 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 serv...

  • Page 6

    6 to install and test the server-side actionscript file, do the following: 1 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 applic...

  • Page 7

    Server-side communication actionscript 7 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 (/) separat...

  • Page 8

    8 clearinterval clearinterval clearsharedobject application.Clearsharedobjects clearstreams application.Clearstreams client client (object) clients application.Clients close netconnection.Close, sharedobject.Close "commandname" client."commandname" connect netconnection.Connect disconnect applicatio...

  • Page 9

    Server-side communication actionscript 9 application (object) the application object contains information about a flash communication server application instance that lasts until the application instance is unloaded. A flash communication server application is a collection of stream objects, shared ...

  • Page 10

    10 method summary for the application object property summary for the application object event handler summary for the application object application.Acceptconnection availability flash communication server mx. Usage application.Acceptconnection(clientobj) parameters clientobj a client to accept. Re...

  • Page 11

    Server-side communication actionscript 11 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 is called from the client side. You can use the application.Accep...

  • Page 12

    12 the following are possible values for the sopath parameter: • / clears all local and persistent shared objects associated with the instance. • /foo/bar clears the shared object /foo/bar ; if bar is a directory name, no shared objects are deleted. • /foo/bar/* clears all shared objects stored unde...

  • Page 13

    Server-side communication actionscript 13 the following are possible values for the streampath parameter: • / clears all recorded streams associated with the instance. • /foo/bar clears recorded streams /foo/bar; if bar is a directory name, no streams are deleted. • /foo/bar/* clears all streams sto...

  • Page 14

    14 example this example uses a for loop to iterate through each member of the application.Clients array and calls the method serverupdate on each client: for (i = 0; i application.Clients[i].Call("serverupdate"); } application.Disconnect availability flash communication server mx. Usage application....

  • Page 15

    Server-side communication actionscript 15 example the following example checks the name property against a specific string before it executes some code: if (application.Name == "videomail/work"){ // insert code here } application.Onappstart availability flash communication server mx. Usage applicati...

  • Page 16

    16 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 false , the application doesn’t unload. If you ...

  • Page 17

    Server-side communication actionscript 17 p1 ..., pn optional parameters passed to the application.Onconnect method. These parameters are passed from the client-side netconnection.Connect method when a client connects to the application. Returns the value you provide. If you return a boolean value o...

  • Page 18

    18 description event handler; invoked on the server side when netconnection.Connect is called from the client side and a client attempts to connect to an application instance. You can define a function for the application.Onconnect event handler. If you don’t define a function, connections are accep...

  • Page 19

    Server-side communication actionscript 19 usage application.Ondisconnect = function (clientobj){ // insert code here }; parameters clientobj a client disconnecting from the application. Returns the server ignores any return value. Description event handler; invoked when a client disconnects from the...

  • Page 20

    20 example the following example defines a function that sends a trace statement whenever the application.Onstatus.

  • Page 21

    Server-side communication actionscript 21 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 color construc...

  • Page 22

    22 parameters methodname the name of a method. All requests to execute methodname for this application instance are forwarded to the proxyconnection object. Proxyconnection a client or netconnection object. All requests to execute the remote method specified by methodname are sent to the client or n...

  • Page 23

    Server-side communication actionscript 23 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 application.Onconnect , you can either accept...

  • Page 24

    24 clearinterval availability flash communication server mx. Usage clearinterval(intervalid) parameters intervalid a unique id returned by a previous call to the setinterval method. Returns nothing. Description method (global); cancels a time-out that was set with a call to the setinterval method. E...

  • Page 25

    Server-side communication actionscript 25 if all instances of the client object (each client in an application) require the same methods or properties, you can add those methods and properties to the class itself instead of adding them to each instance of a class. This process is called extending a ...

  • Page 26

    26 the methods are available to any instance, so within application.Onconnect , which is passed a clientobj argument, you can write the following code: application.Onconnect(clientobj){ var clientid = clientobj.Createuniqueid(); var clientwriteperm = clientobj.Getwritepermission(); }; method summary...

  • Page 27

    Server-side communication actionscript 27 example the following example checks the agent property against the string "win" and executes different code depending on whether they match. This code is written inside an onconnect function. Function onconnect(newclient, name){ if (newclient.Agent.Indexof(...

  • Page 28

    28 the following server-side script uses the client.Call method inside the application.Onconnect handler to call the random method that was defined on the client side. The server-side script also defines a function called randhander , which is used in the client.Call method as the resultobj paramete...

  • Page 29

    Server-side communication actionscript 29 the sum method can then be called from netconnection.Call on the flash client side, as shown in the following example: nc = new netconnection(); nc.Connect("rtmp://myserver/myapp"); nc.Call("sum", new result.Sum(), 20, 50); function result.Sum(){ this.Onresu...

  • Page 30

    30 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 idirection parameter to get the value for each direction of the connection. The value returned indicates bytes per second and can be...

  • Page 31

    Server-side communication actionscript 31 by default, all clients have full read access, and the readaccess property is set to slash ( / ). To give 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...

  • Page 32

    32 parameters propname the name of an undefined property. Returns the value of the undefined property, which is specified by the propname parameter. Description method; provides values for undefined properties. When an undefined property of a client object is referenced by server-side actionscript c...

  • Page 33

    Server-side communication actionscript 33 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 directo...

  • Page 34

    34 note: for security reasons, your server-side applications directory, which contains asc files, audio/video flv files, and actionscript fla source files, should not be accessible to a user browsing your web site. Example the following example loads the myloadedfile.As file: load("myloadedfile.As")...

  • Page 35

    Server-side communication actionscript 35 method summary for the netconnection object property summary for the netconnection object event handler summary for the netconnection object constructor for the netconnection object availability flash communication server mx. Usage new netconnection() parame...

  • Page 36

    36 parameters name a string that identifies the header and the actionscript object data associated with it. Mustunderstand a boolean value; true indicates that the server must understand and process this header before it handles any of the following headers or messages. Object any actionscript objec...

  • Page 37

    Server-side communication actionscript 37 description method; invokes a command or method on a flash communication server or an application server to which the application instance is connected. The netconnection.Call method on the server works the same way as the netconnection.Call method on the cl...

  • Page 38

    38 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 uri a uri to connect to. P1, ..., pn optional parameters that can be of any ac...

  • Page 39

    Server-side communication actionscript 39 usage mynetconnection.Isconnected description property (read-only); a boolean value that indicates whether a connection has been made. It is set to true if there is a connection to the server. It’s a good idea to check this property value in the onstatus cal...

  • Page 40

    40 example this example defines a function for the onstatus handler that outputs messages to indicate whether the netconnection was successful: nc = new netconnection(); nc.Onstatus = function(info){ if (info.Code == "netconnection.Connect.Success") { _root.Gotoandstop(2); } else { if (! Nc.Isconnec...

  • Page 41

    Server-side communication actionscript 41 description method (global); continually calls a function or method at a specified time interval until the clearinterval method is called. This method allows a server-side script to run a generic routine. The setinterval method returns a unique id that you c...

  • Page 42

    42 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 sh...

  • Page 43

    Server-side communication actionscript 43 method summary for the sharedobject object property summary for the sharedobject object event summary for the sharedobject object sharedobject.Clear availability flash communication server mx. Usage sharedobject.Clear() method description sharedobject.Clear ...

  • Page 44

    44 parameters none. Returns returns true if successful; false otherwise. 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 use sharedobjec...

  • Page 45

    Server-side communication actionscript 45 sharedobject.Flush availability flash communication server mx. Usage sharedobject.Flush() parameters none. Returns a boolean value of true if successful, false otherwise. Description method; causes the server to save the current state of the shared object in...

  • Page 46

    46 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 sharedobject.Get method. If the object requested is not found, a new instance is created. There...

  • Page 47

    Server-side communication actionscript 47 example this example creates a shared object named foo inside the function onprocesscmd . The function is passed a parameter, cmd , that is assigned to a property in the shared object. Function onprocesscmd(cmd){ // insert code here var shobj = sharedobject....

  • Page 48

    48 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 re...

  • Page 49

    Server-side communication actionscript 49 the this keyword used in the body of the function is set to the shared object instance returned by 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 ...

  • Page 50

    50 example this example outputs foo 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 info an information object. For more...

  • Page 51

    Server-side communication actionscript 51 local shared objects note: changing or deleting a property on the server side using the sharedobject.Setproperty method always succeeds, so there is no notification of these changes. Proxied shared objects note: the sharedobject.Onsync method is called when ...

  • Page 52

    52 example the following example creates a function that is invoked whenever a property of the shared object so 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...

  • Page 53

    Server-side communication actionscript 53 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 s...

  • Page 54

    54 returns a boolean value of true if the message was sent to the client; false otherwise. Description method; executes a method in a client-side script. You can use sharedobject.Send to asynchronously execute a method on all the flash clients subscribing to a shared object. The server does not rece...

  • Page 55

    Server-side communication actionscript 55 if you call sharedobject.Setproperty on the server side, it invokes a change message in the sharedobject.Onsync method on the client side for any flash player client that is using the shared object. The name parameter on the server side is the same as an att...

  • Page 56

    56 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 ac...

  • Page 57

    Server-side communication actionscript 57 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...

  • Page 58

    58 stream.Clear availability flash communication server mx. Usage stream.Clear() parameters none. Returns a boolean value of true if the call succeeds, false otherwise. Description method; deletes a stream that uses previously recorded by the server. Example this example deletes a recorded stream ca...

  • Page 59

    Server-side communication actionscript 59 example this example gets the stream foo and assigns it to the variable playstream . It then calls the stream.Play method from playstream . Function onprocesscmd(cmd){ var playstream = stream.Get("foo"); playstream.Play("file1", 0, -1); } stream.Length avail...

  • Page 60

    60 usage mystream.Onstatus = function([infoobject]) { // insert code here }; parameters infoobject an optional parameter defined according to the status message. For details about this parameter, see the appendix, “server-side information objects,” on page 67. Returns nothing. Description event hand...

  • Page 61

    Server-side communication actionscript 61 reset a boolean value that flushes the playing stream. If reset is false , the server maintains a playlist, and each call to stream.Play is appended to the end of the playlist so that the next play does not start until the previous play finishes. You can use...

  • Page 62

    62 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 + ""); // tell all the clients for (var i = 0; i application.C...

  • Page 63

    Server-side communication actionscript 63 parameters flag this parameter can have the value record , append , or false . If the value is record , the data file is overwritten if it exists. If the value is append , the incoming data is appended to the end of the existing file. If the value is false ,...

  • Page 64

    64 description method; calls a method on all the clients subscribing to a stream. When you call stream.Send on 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 stream.Send . There should be one str...

  • Page 65

    Server-side communication actionscript 65 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 trace message is also published to the logs/...

  • Page 66

    66.

  • Page 67: Appendix

    67 appendix server-side information objects the application, netconnection, and stream 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 informati...

  • Page 68

    Appendix 68 netconnection information objects the netconnection object has the same information objects as the client-side netconnection object. Stream information objects the information objects of the stream object are similar to those of the client-side netstream object. Application.Resource.Lowm...

  • Page 69

    Server-side information objects 69 netstream.Failed error an attempt to use a stream method failed.* netstream.Unpublish.Success status an attempt to unpublish was successful. Netstream.Record.Start status recording was started. Netstream.Record.Noaccess error an attempt was made to record a read-on...