Summary of FLASH MEDIA SERVER 2-SERVER-SIDE ACTIONSCRIPT LANGUAGE

  • Page 1

    Server-side actionscript language reference.

  • Page 2

    Trademarks 1 step robopdf, activeedit, activetest, authorware, blue sky software, blue sky, breeze, breezo, captivate, central, coldfusion, contribute, database explorer, director, dreamweaver, fireworks, flash, flashcast, flashhelp, flash lite, flashpaper, flash video encoder, flex, flex builder, f...

  • Page 3

    3 contents chapter 1: server-side actionscript language reference . . . . . . 5 using server-side actionscript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 using naming conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 actionscript...

  • Page 4

    4 contents.

  • Page 5

    5 1 chapter 1 server-side actionscript language reference server-side actionscript is a scripting language on the server that lets you develop efficient and flexible client-server macromedia flash media server applications. For example, you can use server-side actionscript to control log-in procedur...

  • Page 6

    6 server-side actionscript language reference create the server-side actionscript file and name it main.Asc. All actionscript code that is embedded in the script file and not in a function body executes once when the application is loaded but before the application.Onappstart event handler is called...

  • Page 7

    Using naming conventions 7 4. Place the main.Asc file in the appname directory or in a subdirectory called scripts in the appname directory. 5. Open the flash application (the swf file) in a browser or in the stand-alone flash player. The swf file must contain actionscript code that passes appname t...

  • Page 8

    8 server-side actionscript language reference avoiding reserved commands flash media server has reserved commands that you cannot use in a script. These commands are either methods that belong to the client-side netconnection class or methods that belong to the server-side client class. This means t...

  • Page 9

    Global functions 9 global functions the following table lists all the global functions in the server-side actionscript language reference. Stream class the stream class lets you handle each stream in a flash media server application. Webservice class the webservices class lets you create and access ...

  • Page 10

    10 server-side actionscript language reference actionscript elements entries in this document are alphabetical by class name and then by method, property, or event handler name. The following table lists all classes, methods, properties, and event handlers individually in alphabetical order. Actions...

  • Page 11

    Actionscript elements 11 config application.Config connect netconnection.Connect() , xmlsocket.Connect() contenttype loadvars.Contenttype , xml.Contenttype copyto file.Copyto() createelement xml.Createelement() createtextnode xml.Createtextnode() creationtime file.Creationtime decode loadvars.Decode...

  • Page 12

    12 server-side actionscript language reference hostname application.Hostname ignorewhite xml.Ignorewhite insertbefore xml.Insertbefore() ip client.Ip isconnected netconnection.Isconnected isdirectory file.Isdirectory isdirty sharedobject.Isdirty isfile file.Isfile isopen file.Isopen lastchild xml.La...

  • Page 13

    Actionscript elements 13 onconnect application.Onconnect , xmlsocket.Onconnect onconnectaccept application.Onconnectaccept onconnectreject application.Onconnectreject ondata loadvars.Ondata , xml.Ondata , xmlsocket.Ondata ondisconnect application.Ondisconnect onfault soapcall.Onfault , webservice.On...

  • Page 14

    14 server-side actionscript language reference referrer client.Referrer registerclass application.Registerclass() registerproxy application.Registerproxy() rejectconnection application.Rejectconnection() remove file.Remove() removenode xml.Removenode() renameto file.Renameto() request soapcall.Reque...

  • Page 15

    Application class 15 application class availability flash communication server 1. The application class contains information about a flash media server application instance that lasts until the application instance is unloaded. A flash media server application is a collection of stream objects, shar...

  • Page 16

    16 server-side actionscript language reference besides the built-in properties of the application class, you can create other properties of any legal actionscript type, including references to other actionscript objects. For example, the following code creates a new property of type array and a new ...

  • Page 17

    Application class 17 event handler summary for the application class application.Acceptconnection() availability flash communication server mx 1.0. Usage application.Acceptconnection(clientobj) parameters clientobj a client object; a client to accept. Returns nothing. Application.Config lets you acc...

  • Page 18

    18 server-side actionscript language reference 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 applicatio...

  • Page 19

    Application class 19 description property; a boolean value that allows administrators to access your application with the approvedebugsession() server management api ( true ) or not ( false ). A debug connection displays information about shared objects and streams. For information about creating a ...

  • Page 20

    20 server-side actionscript language reference see also sharedobject.Handlername application.Clearsharedobjects() availability flash communication server mx 1.0. Usage application.Clearsharedobjects(sopath) parameters sopath a string that indicates the uri of a shared object. Returns a boolean value...

  • Page 21

    Application class 21 if you call the clearsharedobjects() method and the specified path matches a shared object that is currently active, all its properties are deleted, and a “clear” event is sent to all subscribers of the shared object. If it is a persistent shared object, the persistent store is ...

  • Page 22

    22 server-side actionscript language reference the streampath parameter specifies the location and name of a stream, relative to the application’s instance directory. You can include a slash (/) as a delimiter between directories in the path. The last element in the path can contain wildcard pattern...

  • Page 23

    Application class 23 example the following example clears all recorded streams: function onapplicationstop(){ application.Clearstreams("/"); } the following example clears all mp3 files from the application instance’s /disco subdirectory: function onapplicationstop(){ application.Clearstreams("mp3:/...

  • Page 24

    24 server-side actionscript language reference example the following 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.Config availability ...

  • Page 25

    Application class 25 application.Disconnect() availability flash communication server mx 1.0. Usage application.Disconnect(clientobj) parameters clientobj the client to disconnect. The object must be a client object from the application.Clients array. Returns a boolean value of true if the disconnec...

  • Page 26

    26 server-side actionscript language reference returns nothing. Description method; invokes the garbage collector to reclaim any unused resources for this application instance. Application.Getstats() availability flash communication server mx 1.0. Usage application.Getstats() returns an actionscript...

  • Page 27

    Application class 27 usage application.Hostname description property (read-only); contains the host name of the server for default virtual hosts and the virtual host name for non-default virtual hosts. Example the following example traces the name of the host running the current application: trace(a...

  • Page 28

    28 server-side actionscript language reference returns nothing. Description event handler; invoked when the server first loads the application instance. You use this handler to initialize an application state. You can use application.Onappstart and application.Onappstop to initialize and clean up gl...

  • Page 29

    Application class 29 the flash media server application passes an information object to the application.Onappstop event. You can use server-side actionscript to look at this information object to decide what to do in the function you define. You could also define the application.Onappstop event to n...

  • Page 30

    30 server-side actionscript language reference returns the value you provide. If you return a boolean value of true , the server accepts the connection; if the value is false , the server rejects the connection. If you return null or no return value, the server puts the client in a pending state and...

  • Page 31

    Application class 31 how to use application.Onconnect to accept, reject, or put a client in a pending state. 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 f...

  • Page 32

    32 server-side actionscript language reference if there are several simultaneous connection requests for an application, the server serializes the requests so there is only one application.Onconnect handler executing at a time. It is a good idea to write code for the application.Onconnect function t...

  • Page 33

    Application class 33 if the password is incorrect, the user is rejected and an information object with a message property set to “invalid password” is returned to the client side. The object is assigned to infoobject.Application . To access the message property, use the following code on the client ...

  • Page 34

    34 server-side actionscript language reference if you don’t use the flash media server components framework, you can execute code in the application.Onconnect handler after accepting or rejecting the connection. When you use the components framework, however, any code you want to execute after the c...

  • Page 35

    Application class 35 see also application.Acceptconnection() , application.Onconnect , application.Onconnectreject , application.Rejectconnection() application.Onconnectreject availability flash media server (with communication components only). Usage application.Onconnectreject = function (clientob...

  • Page 36

    36 server-side actionscript language reference example the following example is the client-side code you can use for an application: nc = new netconnection(); nc.Connect("rtmp:/test","jlopes"); nc.Onstatus = function(info) { trace(info.Code); }; nc.Dosomething = function(){ trace("dosomething called...

  • Page 37

    Application class 37 application.Ondisconnect availability flash communication server mx 1.0. Usage application.Ondisconnect = function (clientobj){} parameters clientobj a client object; a client disconnecting from the application. Returns the server ignores any return value. Description event hand...

  • Page 38

    38 server-side actionscript language reference returns any value that the callback function returns. Description event handler; invoked when the server encounters an error while processing a message that was targeted at this application instance. The application.Onstatus event handler is the root fo...

  • Page 39

    Application class 39 returns nothing. Description method; registers a constructor function that is used when deserializing an object of a certain class type. If the constructor for a class is not registered, you cannot call the deserialized object’s methods. This method is also used to unregister th...

  • Page 40

    40 server-side actionscript language reference example the following example defines a color constructor function with properties and methods. After the application connects, the registerclass method is called to register a class for the objects of type color . When a typed object is sent from the c...

  • Page 41

    Application class 41 application.Registerproxy() availability flash communication server mx 1.0. Usage application.Registerproxy(methodname, proxyconnection [, proxymethodname]) parameters methodname the name of a method. All requests to execute methodname for this application instance are forwarded...

  • Page 42

    42 server-side actionscript language reference example in the following example, the application.Registerproxy method is called in a function in the application.Onappstart event handler and executes when the application starts. In the function block, a new netconnection object called myproxy is crea...

  • Page 43

    Application class 43 when you use components and your code includes an explicit call to application.Acceptconnection or application.Rejectconnection , the last line (in order of execution) of the onconnect method should be either application.Acceptconnection or application.Rejectconnection . Also, a...

  • Page 44

    44 server-side actionscript language reference application.Server availability flash communication server mx 1.0. Usage application.Server description property (read-only); contains the platform and the server-version information. Example the following example checks the server property against a st...

  • Page 45

    Application class 45 description method; unloads the application instance. If the application is running in vhost or application-level scope, only the application instance is unloaded, but the core process remains running. If the application is running in instance scope, the application instance is ...

  • Page 46

    46 server-side actionscript language reference clearinterval() availability flash communication server mx 1.0. 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 t...

  • Page 47

    Client class 47 client class availability flash communication server 1. The client class lets you handle each user, or client, connection to a flash media server application instance. The server automatically creates a client object when a user connects to an application; the object is destroyed whe...

  • Page 48

    48 server-side actionscript language reference the previous example works, but must be executed every time a client connects. If you want the same methods and properties to be available to all clients in the application.Clients array without defining them every time, you must assign them to the prot...

  • Page 49

    Client class 49 method summary for the client class property summary for the client class method description client.Call() executes a method on the flash client asynchronously and returns the value from the flash client to the server. Client.Getbandwidthlimit() returns the maximum bandwidth the clie...

  • Page 50

    50 server-side actionscript language reference event handler summary for the client class client.Agent availability flash communication server mx 1.0. Usage clientobject.Agent description property (read-only); contains the version and platform information of the flash client. Example the following e...

  • Page 51

    Client class 51 usage clientobject.Call(methodname, [resultobj, [p1, ..., pn]]) parameters methodname a method specified in the form [objectpath/]method . For example, the command someobj/dosomething tells the client to invoke the netconnection.Someobj.Dosomething method on the client. Resultobj an ...

  • Page 52

    52 server-side actionscript language reference the following server-side script uses the client.Call() method in 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 th...

  • Page 53

    Client class 53 example the following example creates a method called sum as a property of the client object newclient on the server side: newclient.Sum = function sum(op1, op2){ return op1 + op2; }; the sum() method can then be called from netconnection.Call() on the flash client side, as shown in ...

  • Page 54

    54 server-side actionscript language reference you can call either of the two functions that were defined in the previous examples ( foo and bar ) by using the following code in a server-side script: c = new netconnection(); c.Onstatus = function(info) { if(info.Code == "netconnection.Connect.Succes...

  • Page 55

    Client class 55 client.Getstats() availability flash communication server mx 1.0. Usage clientobject.Getstats() returns an object with various properties for each statistic returned. Description method; returns statistics for the client including the total number of bytes sent and received, the numb...

  • Page 56

    56 server-side actionscript language reference example the following example uses the client.Ip property to verify whether a new client has a specific ip address. The result determines which block of code runs. Application.Onconnect = function(newclient, name){ if (newclient.Ip == "127.0.0.1"){ // i...

  • Page 57

    Client class 57 client.Protocol availability flash communication server mx 1.0 usage clientobject.Protocol description property (read-only); a string indicating the protocol used by the client to connect to the server. This string can have one of the following values: ■ rtmp (rtmp over a persistent ...

  • Page 58

    58 server-side actionscript language reference client.Readaccess availability flash communication server mx 1.0. Usage clientobject.Readaccess description property; a string that provides read-access rights to directories that contain application resources (shared objects and streams) for this clien...

  • Page 59

    Client class 59 client.Referrer availability flash communication server mx 1.0. Usage clientobject.Referrer description property (read-only); a string whose value is set to the url of the swf file or the server in which this connection originated. Example the following example defines an onconnect c...

  • Page 60

    60 server-side actionscript language reference example the following example defines a function that is called whenever an undefined property is referenced: client.Prototype.__resolve = function (name) { return "hello, world!"; }; function onconnect(newclient){ // prints "hello world". Trace (newcli...

  • Page 61

    Client class 61 returns nothing. Description method; sets the maximum bandwidth for this client from client to server, server to client, or both. The default value for a connection is set for each application in the application.Xml file. The value specified cannot exceed the bandwidth cap value spec...

  • Page 62

    62 server-side actionscript language reference client.Virtualkey availability flash media server 2. Usage clientobject.Virtualkey description property; the user agent type of the client, which is typically the flash player version, but can be set to any legal key value. A legal key can contain be an...

  • Page 63

    File class 63 example the following example provides write access to the /mymedia/mystreams and mydata/notes directories. Application.Onconnect = function(newclient, name){ newclient.Writeaccess = "/mymedia/mystreams;mydata/notes"; application.Acceptconnection(); }; see also client.Readaccess file c...

  • Page 64

    64 server-side actionscript language reference ■ root objects cannot be renamed or deleted. For example, if a path using the slash (/) is used to create a file object, the application folder is mapped. ■ applications can be granted access to additional directories by specifying virtual directory map...

  • Page 65

    File class 65 method summary for the file class method description file.Close() closes the file. File.Copyto() copies a file to a different location or to the same location with a different filename. File.Eof() returns a boolean value indicating whether the file pointer is at the end of file ( true ...

  • Page 66

    66 server-side actionscript language reference property summary for the file class property description file.Canappend read-only; a boolean value indicating whether a file was open for appending ( true ) or not ( false ). File.Canread read-only; a boolean value indicating whether a file can be read ...

  • Page 67

    File class 67 constructor for the file class availability flash media server 2. Usage fileobject = new file( name ) parameters name specifies the name of the file or directory. The name can contain only utf-8 encoded characters; high byte values can be encoded using the uri character- encoding schem...

  • Page 68

    68 server-side actionscript language reference file.Canread availability flash media server 2. Usage fileobject.Canread description property (read-only); a boolean value indicating whether a file can be read ( true ) or not ( false ). File.Canreplace availability flash media server 2. Usage fileobje...

  • Page 69

    File class 69 description property (read-only); a boolean value indicating whether you can write to a file ( true ) or not ( false ). File.Close() availability flash media server 2. Usage fileobject.Close() parameters none. Returns a boolean value indicating whether the file was closed successfully ...

  • Page 70

    70 server-side actionscript language reference file.Copyto() availability flash media server 2. Usage fileobject.Copyto(name) parameters name specifies the name of the destination file. The name can contain only utf-8 characters; high byte values can be encoded using the uri character-encoding schem...

  • Page 71

    File class 71 file.Eof() availability flash media server 2. Usage fileobject.Eof() parameters none. Returns a boolean value. Description method; returns a boolean value indicating whether the file pointer is pointing to the end of file ( true ) or not ( false ). If the file is closed, the method ret...

  • Page 72

    72 server-side actionscript language reference file.Flush() availability flash media server 2. Usage fileobject.Flush() parameters returns a boolean value; returns a boolean value indicating whether the flush operation was successful ( true) or not ( false). Description method; flushes the output bu...

  • Page 73

    File class 73 the following example uses named property lookup to refer to files that do not have valid property names: mysamefileindir = mydir["foo"]; myotherfile = mydir["some long filename with spaces and such"]; file.Isfile availability flash media server 2. Usage fileobject.Isfile description p...

  • Page 74

    74 server-side actionscript language reference description property (read-only); a date object containing the time the file was last modified. File.Length availability flash media server 2. Usage fileobject.Length description property (read-only). For a directory, the number of files in the director...

  • Page 75

    File class 75 file.Mkdir() availability flash media server 2. Usage fileobject.Mkdir(newdir) parameters newdir a string indicating the name of the new directory. This name is relative to the current file object instance. Returns a boolean value indicating success ( true ) or failure ( false ). Descr...

  • Page 76

    76 server-side actionscript language reference file.Name availability flash media server 2. Usage fileobject.Name description property (read-only); a string indicating the name of the file. The value is an empty string if the file object was created with a invalid path. File.Open() availability flas...

  • Page 77

    File class 77 returns a boolean value indicating whether the file opened successfully ( true ) or not ( false ). Description method; opens a file so that you can read from it or write to it. First, you must create a file object and then call the open() method on that object. There are no default val...

  • Page 78

    78 server-side actionscript language reference returns a string. Description method; reads the specified number of characters from a file and returns a string. The operation will fail if the file is opened in binary mode. Example the following code opens a text file in read mode and sets variables f...

  • Page 79

    File class 79 file.Readbyte() availability flash media server 2. Usage fileobject.Readbyte() parameters returns a number; either a positive integer or -1. Description method; reads the next byte from the file and returns the numeric value of the next byte or -1 if the operation fails. The operation ...

  • Page 80

    80 server-side actionscript language reference see also file.Read() , file.Readall() , file.Readbyte() file.Remove() availability flash media server 2. Usage fileobject.Remove() parameters none. Returns a boolean value indicating whether the file or directory was removed successfully ( true ) or not...

  • Page 81

    File class 81 parameters name the new name for the file or directory. The name can contain only utf-8 encoded characters; high byte values can be encoded using the uri character-encoding scheme. The specified name is mapped to a system path using the mappings specified in the application.Xml file. I...

  • Page 82

    82 server-side actionscript language reference description method; skips a specified number of bytes and returns the new file position. This method can accept both positive and negative parameters. Example in the following example, if the seek call is successful, the code in the if statement runs: i...

  • Page 83

    File class 83 description property (read-only); a string specifying the type of data or encoding used when a file is opened. The following strings are supported: "text" , "utf8" , and "binary" . The property is undefined for directories and closed files. If the file is opened in “text” mode and utf-...

  • Page 84

    84 server-side actionscript language reference file.Writeall() availability flash media server 2. Usage fileobject.Writeall(array) parameters array an array object containing all the elements to write to the file. Returns a boolean value indicating whether the write was successful ( true ) or not ( ...

  • Page 85

    File class 85 the file contents are buffered internally. The file.Flush() method writes the buffer to the file on disk. Example the following example writes byte 65 to the end of the myfileobject file: if (myfileobject.Open("text","append")) { myfileobject.Writebyte(65); } see also file.Write() , fi...

  • Page 86

    86 server-side actionscript language reference getglobal() availability flash media server 2. Usage getglobal() parameters none. Returns nothing. Description method (global); provides access to the global object while the secure.Asc file is loading. Use the global object to manipulate built-in globa...

  • Page 87

    Loadvars class 87 load() availability flash communication server mx 1.0. Usage load(filename) parameters filename the relative path to an actionscript file from the main.Asc file. Returns nothing. Description method (global); loads an actionscript file in the main.Asc file. This method executes only...

  • Page 88

    88 server-side actionscript language reference the loadvars class works much like the xml class; it uses the load() , send() , and sendandload() methods to communicate with a server. The main difference between the loadvars class and the xml class is that loadvars transfers actionscript name and val...

  • Page 89

    Loadvars class 89 property summary for the loadvars class event summary for the loadvars class constructor for the loadvars class availability flash media server 2. Usage new loadvars() parameters none. Description constructor; creates a loadvars object. You can use the methods of the loadvars objec...

  • Page 90

    90 server-side actionscript language reference loadvars.Addrequestheader() availability flash media server 2. Usage myloadvars.Addrequestheader(header, headervalue) parameters header a string or array of strings that represents an http request header name. Headervalue a string that represents the va...

  • Page 91

    Loadvars class 91 the following example creates a new loadvars object that adds a request header called flash-uuid. The header contains a variable that the server can check. Var my_lv = new loadvars(); my_lv.Addrequestheader("flash-uuid", "41472"); my_lv.Name = "mort"; my_lv.Age = 26; my_lv.Send("ht...

  • Page 92

    92 server-side actionscript language reference description method; converts the query string to properties of the specified loadvars object. This method is used internally by the loadvars.Ondata event handler. Most users do not need to call this method directly. If you override the loadvars.Ondata e...

  • Page 93

    Loadvars class 93 loadvars.Getbytestotal() availability flash media server 2. Usage myloadvars.Getbytestotal() parameters none. Returns a number object. The getbytestotal() method returns undefined if no load operation is in progress or if a load operation has not been initiated. The getbytestotal()...

  • Page 94

    94 server-side actionscript language reference returns a boolean value indicating success ( true ) or failure ( false ). Description method; downloads variables from the specified url, parses the variable data, and places the resulting variables into a loadvars object ( myloadvars ). You can load va...

  • Page 95

    Loadvars class 95 example the following example loads a text file and writes information to the log file when the operation completes: var my_lv = new loadvars(); my_lv.Onload = function(success) { trace("loadvars loaded successfully: "+this.Loaded); }; my_lv.Load("http://www.Helpexamples.Com/flash/...

  • Page 96

    96 server-side actionscript language reference example the following example loads a text file and displays content in a textarea instance called content_ta when the operation completes. If an error occurs, then information displays in the output panel. If an error occurs, then information writes to...

  • Page 97

    Loadvars class 97 example the following example shows how to use onhttpstatus to help with debugging. The example collects http status codes and assigns their value and type to an instance of the loadvars object. (notice that this example creates the instance members this.Httpstatus and this.Httpsta...

  • Page 98

    98 server-side actionscript language reference loadvars.Onload availability flash media server 2. Usage myloadvars.Onload(success){} parameters success a boolean value indicating whether the loadvars.Load() operation ended in success ( true ) or failure ( false ). Description event handler; invoked ...

  • Page 99

    Loadvars class 99 parameters url a string; the url to which to upload variables. Target a file object. If you use this optional parameter, any returned data is output to the specified file object. If this parameter is omitted, the response is discarded. Method a string indicating the get or post met...

  • Page 100

    100 server-side actionscript language reference description method; posts the variables in the myloadvars object to the specified url. The server response is downloaded, parsed as variable data, and the resulting variables are placed in the target object. Variables are posted in the same way as load...

  • Page 101

    Log class 101 log class availability flash media server 2. The log class lets you create a log object that can be passed as an optional argument to the constructor for the webservice class. For more information, see “constructor for the webservice class” on page 164 . Event handler summary for the l...

  • Page 102

    102 server-side actionscript language reference example the following example creates a new instance of the log class: newlog = new log(); log.Onlog availability flash media server 2. Usage mylog.Onlog(message){} parameters message a log message. Returns nothing. Description event handler; invoked w...

  • Page 103

    Netconnection class 103 method summary for the netconnection class property summary for the netconnection class event handler summary for the netconnection class constructor for the netconnection class availability flash communication server mx 1.0. Usage new netconnection() parameters none. Returns...

  • Page 104

    104 server-side actionscript language reference description constructor; creates a new instance of the netconnection class. Example the following example creates a new instance of the netconnection class: newnc = new netconnection(); netconnection.Addheader() availability flash communication server ...

  • Page 105

    Netconnection class 105 netconnection.Call() availability flash communication server mx 1.0. Usage mynetconnection.Call(methodname, [resultobj, p1, ..., pn]) parameters methodname a method specified in the form [objectpath/]method . For example, the command someobj/dosomething tells the remote serve...

  • Page 106

    106 server-side actionscript language reference the following server-side actionscript code is on server 2. When the client is connecting, this code checks to see whether it has an argument that is equal to svr1 . If the client has that argument, the sum method is defined so that when the method is ...

  • Page 107

    Netconnection class 107 example the following code closes the netconnection instance mynetconn : mynetconn.Close(); netconnection.Connect() availability flash communication server mx 1.0. Usage mynetconnection.Connect(uri, [p1, ..., pn]) parameters uri a uri to connect to. P1, ..., pn optional param...

  • Page 108

    108 server-side actionscript language reference it is good practice to write an application.Onstatus callback function and check the netconnection.Isconnected property for rtmp connections to see whether a successful connection was made. For action message format connections, check netconnection.Ons...

  • Page 109

    Netconnection class 109 ■ if the application.Allowdebug property is true , the connection is approved. To provide total security against debug connections, set application.Allowdebug to false in the application.Xml file. This setting overrides debug connections that are approved in server-side code....

  • Page 110

    110 server-side actionscript language reference the following example creates a debug connection: nc_admin = new netconnection(); nc_admin.Connect("rtmp://tc.Foo.Com/myapp/myconn?_fcs_debugreq_=1234"); nc_admin.Call("approvedebugsession", null, "myapp/myconn", 1234); netconnection.Isconnected availa...

  • Page 111

    Netconnection class 111 returns nothing. Description event handler; invoked every time the status of the netconnection object changes. For example, if the connection with the server is lost in an rtmp connection, the netconnection.Isconnected property is set to false , and netconnection.Onstatus is ...

  • Page 112

    112 server-side actionscript language reference protectobject() availability flash media server 2. Usage protectobject(userobj) parameters userobj an object to wrap in a c wrapper object. Returns an object. Description method (global); protects user-defined or built-in objects behind a c wrapper obj...

  • Page 113

    Setattributes() 113 example after secure.Asc is executed, calls to load() are directed through the user-defined system call, as shown in the following example: var sysobj = {}; sysobj._load = load; // hide the load function load = null; // make it unavailable unpriviliged code sysobj.Load = function...

  • Page 114

    114 server-side actionscript language reference parameters obj an object. Propname a string; the url to upload variables. The name of the property that exists in the obj parameter. Setting attributes on nonexistent properties has no effect. Enumerable one of the following values: true , false , or n...

  • Page 115

    Setinterval() 115 setinterval() availability flash communication server mx 1.0. Usage setinterval(function, interval[, p1, ..., pn]) setinterval(object, methodname, interval[, p1, ..., pn]) parameters function the name of a defined actionscript function or a reference to an anonymous function. Objec...

  • Page 116

    116 server-side actionscript language reference the following example uses a named function, callback1 , to send the message “interval called” to the server log: function callback1(){ trace("interval called"); } setinterval(callback1, 1000); the following example also uses a named function, callback...

  • Page 117

    Sharedobject class 117 ■ sharing data in real time a shared object can share data among multiple clients in real time. For example, you can open a remote shared object that stores real-time data that is visible to all clients connected to the object, such as a list of users connected to a chat room....

  • Page 118

    118 server-side actionscript language reference when you get a reference to a proxied shared object, any changes made to the object are sent to the instance that owns the object. The success or failure of any changes are sent using the sharedobject.Onsync event handler, if it is defined. The sharedo...

  • Page 119

    Sharedobject class 119 property summary for the sharedobject class event summary for the sharedobject class sharedobject.Autocommit availability flash media server 2. Usage myso.Autocommit description property; a boolean value indicating whether the server periodically stores all persistent shared o...

  • Page 120

    120 server-side actionscript language reference this property is true by default. This can be overridden by specifying the initial state using the following configuration key in the application.Xml file, as shown in the following example: false sharedobject.Clear() availability flash communication s...

  • Page 121

    Sharedobject class 121 parameters none. Returns nothing. Description method; detaches a reference from a shared object. A call to the sharedobject.Get() method returns a reference to a shared object instance. The reference is valid until the variable that holds the reference is no longer in use and ...

  • Page 122

    122 server-side actionscript language reference description method (static); stores either a specific persistent shared object instance or all persistent shared object instances with an isdirty property whose value is true . Use this method if the sharedobject.Autocommit property is false and you ne...

  • Page 123

    Sharedobject class 123 sharedobject.Get() availability flash communication server mx 1.0. Usage sharedobject.Get(name, persistence [, netconnection]) parameters name name of the shared object instance to return. Persistence a boolean value: true for a persistent shared object; false for a nonpersist...

  • Page 124

    124 server-side actionscript language reference you can also call sharedobject.Get() to get a reference to a shared object that is in a namespace of another application instance. This instance can be on the same server or on a different server and is called a proxied shared object. To get a referenc...

  • Page 125

    Sharedobject class 125 example the following example creates a shared object named foo in 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.Get("foo", tr...

  • Page 126

    126 server-side actionscript language reference example the following example gets the value of the name property and passes it to the value variable: value = sharedinfo.Getproperty(name); see also sharedobject.Setproperty() sharedobject.Getpropertynames() availability flash communication server mx ...

  • Page 127

    Sharedobject class 127 sharedobject.Handlername availability flash communication server mx 1.0. Usage myso.Onbroadcastmsg = function([p1,..., pn]){} parameters onbroadcastmsg a property name. P1, ..., pn optional parameters passed to the handler method if the message contains user-defined parameters...

  • Page 128

    128 server-side actionscript language reference sharedobject.Isdirty availability flash media server 2. Usage myso.Isdirty description property (read-only); a boolean value indicating whether a persistent shared object has been modified since the last time it was stored ( true ) or not ( false ). Th...

  • Page 129

    Sharedobject class 129 description method; locks the shared object instance. This method gives the server-side script exclusive access to the shared object; when the sharedobject.Unlock() method is called, all changes are batched and one update message is sent, through the sharedobject.Onsync handle...

  • Page 130

    130 server-side actionscript language reference p1, ..., pn parameters of any actionscript type, including references to other actionscript objects. These parameters are passed to the specified handler when it is executed on the flash client. Returns a boolean value. Returns true if the message can ...

  • Page 131

    Sharedobject class 131 the following example shows the receiving client-side script: connection = new netconnection(); connection.Connect("rtmp://flashmediaserver/someapp"); var x = sharedobject.Get( "foo", connection.Uri, true); x.Connect(connection); x.Onadrchange = function(str) { // shared objec...

  • Page 132

    132 server-side actionscript language reference description event handler; reports errors, warnings, and status messages associated with either a local instance of a shared object or a persistent shared object. Example the following example defines an onstatus event handler for the shared object soi...

  • Page 133

    Sharedobject class 133 proxied shared objects returns nothing. Description event handler; invoked when a shared object changes. Use the onsync handler to define a function that handles changes made to a shared object by subscribers. For proxied shared objects, define the function to get the status o...

  • Page 134

    134 server-side actionscript language reference 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 objec...

  • Page 135

    Sharedobject class 135 returns nothing. Description method; causes the server to purge all deleted properties that are older than the specified version. Although you can also accomplish this task by setting the sharedobject.Resyncdepth property, the sharedobject.Purge() method gives the script more ...

  • Page 136

    136 server-side actionscript language reference this method is useful when you add and delete many properties and you don’t want to send too many messages to the flash client. Suppose a client is connected to a shared object that has 12 properties and then disconnects. After that client disconnects,...

  • Page 137

    Sharedobject class 137 example the following example calls the sharedobject.Send() method to execute the dosomething() method in the client-side actionscript and passes dosomething() the string "this is a test" : var myshared = sharedobject.Get("foo", true); myshared.Send("dosomething", "this is a t...

  • Page 138

    138 server-side actionscript language reference a shared object property can be modified by a client between successive calls to sharedobject.Getproperty() and sharedobject.Setproperty() . If you want to preserve transactional integrity, call the sharedobject.Lock() method before modifying the share...

  • Page 139

    Sharedobject class 139 returns an integer indicating the number of properties. Description method; returns the total number of valid properties in a shared object. Example the following example gets the number of properties of a shared object and assigns that number to the variable len : var myshare...

  • Page 140

    140 server-side actionscript language reference see also sharedobject.Lock() sharedobject.Version availability flash communication server mx 1.0. Usage myso.Version description property (read-only); the current version number of the shared object. Changes made to the shared object either by the flas...

  • Page 141

    Soapcall class 141 soapcall.Onfault availability flash media server 2. Usage mysoapcall.Onfault(fault) parameters fault the fault parameter is an object version of an xml soap fault (see “soapfault class” on page 142 ). Returns nothing. Description event handler; invoked when a method has failed and...

  • Page 142

    142 server-side actionscript language reference soapcall.Request availability flash media server 2. Usage mysoapcall.Request description property; an xml object that represents the current soap request. Soapcall.Response availability flash media server 2. Usage mysoapcall.Response description proper...

  • Page 143

    Soapfault class 143 soapfault.Detail availability flash media server 2. Usage mysoapfault.Detail description property; a string indicating the application-specific information associated with the error, such as a stack trace or other info returned by the web service engine. Soapfault.Faultactor avai...

  • Page 144

    144 server-side actionscript language reference soapfault.Faultstring availability flash media server 2. Usage mysoapfault.Faultstring description property; a string indicating the human-readable description of the error. Example the following example shows the fault code in a text field if the web ...

  • Page 145

    Stream class 145 you can use the properties and methods of the stream class to shuffle streams in a playlist, pull streams from other servers, and play and record streams. You can also use the stream class to play mp3 files over a stream, as well as id3 tags associated with mp3 files. You can create...

  • Page 146

    146 server-side actionscript language reference event handler summary for the stream class stream.Buffertime availability flash communication server mx 1.0. Usage mystream.Buffertime description property (read-only); indicates how long to buffer messages before a stream plays. This property applies ...

  • Page 147

    Stream class 147 example the following example deletes a recorded stream called foo.Flv . Before the stream is deleted, the example defines an onstatus handler that uses two information object error codes, netstream.Clear.Success and netstream.Clear.Failed , to send status messages to the applicatio...

  • Page 148

    148 server-side actionscript language reference it is highly recommended that you call flush() on a stream that contains only data. Synchronization problems can occur if you call the flush() method on a stream that contains data and either audio, video, or both. Example the following example flushes...

  • Page 149

    Stream class 149 stream.Length() availability flash communication server mx 1.0. Usage mystream.Length(name[, virtualkey]) parameters name name of a recorded stream (flv) file or mp3 file. To get the length of an mp3 file, precede the name of the file with mp3: (for example, "mp3:beethoven" ). Virtu...

  • Page 150

    150 server-side actionscript language reference stream.Name availability flash communication server mx 1.0. Usage mystream.Name description property (read-only); contains a unique string associated with a live stream. You can also use this as an index to find a stream within an application. Example ...

  • Page 151

    Stream class 151 example the following example defines a function that executes whenever the stream.Onstatus event is invoked: s = stream.Get("foo"); s.Onstatus = function(info){ // insert code here. }; stream.Play() availability flash communication server mx 1.0. Usage mystream.Play(streamname, [st...

  • Page 152

    152 server-side actionscript language reference length the length of play, in seconds. For a live stream, a value of -1 plays the stream as long as the stream exists. Any positive value plays the stream for the corresponding number of seconds. For a recorded stream, a value of -1 plays the entire fi...

  • Page 153

    Stream class 153 description method; controls the data source of a stream with an optional start time, duration, and reset flag to flush any previously playing stream. The stream.Play() method also has a parameter that lets you reference a netconnection object to play a stream from another server. T...

  • Page 154

    154 server-side actionscript language reference example the following example shows 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...

  • Page 155

    Stream class 155 the following example creates a playlist of three mp3 files ( beethoven.Mp3 , mozart.Mp3 , and chopin.Mp3 ) and plays each file in turn over the live stream foo : application.Mystream = stream.Get("foo"); if(application.Mystream) { application.Mystream.Play("mp3:beethoven", 0); appl...

  • Page 156

    156 server-side actionscript language reference example the following example opens a stream s and, when it is open, plays sample and records it. Because no value is passed to the record method, the default value, record , is passed. // start recording. S = stream.Get("foo"); if (s){ s.Play("sample"...

  • Page 157

    Stream class 157 description method; sends a message to all clients subscribing to the stream and the message is processed by the handler specified on the client. Because the server has higher priority than the clients, the server can still send a message on a stream owned by a client. Unlike the st...

  • Page 158

    158 server-side actionscript language reference stream.Setvirtualpath() availability flash media server 2. Usage mystream.Setvirtualpath(virtualpath, directory, virtualkey) parameters virtualpath a string indicating the virtual directory path of a stream. If the stream is not located in the virtual ...

  • Page 159

    Stream class 159 the following example shows the virtualkeys section from the vhost.Xml file in which the virtual keys can be mapped to a range of flash player versions: by default, there are no values in the key tags. To implement this feature, you must add the key values, either directly in the vh...

  • Page 160

    160 server-side actionscript language reference example the following code sets the virtual key to b, the virtual path to /foo, and the physical directory to c:\streams\on2: mystream.Setvirtualpath("b", "/foo", "c:\streams\on2"); stream.Size() availability flash media server 2. Usage stream.Size(nam...

  • Page 161

    Trace() 161 function onprocesscmd(cmd){ // insert code here... Var streamsize = stream.Size("mp3:foo" ); trace("size: " + streamsize + ""); } stream.Syncwrite availability flash media server 2. Usage mystream.Syncwrite description property; a boolean value that controls when a stream writes the co...

  • Page 162

    162 server-side actionscript language reference parameters expression any valid actionscript expression. Returns nothing. Description method (global); evaluates an expression and displays the value. The expression appears in the console window when the server is running in console mode; the expressi...

  • Page 163

    Webservice class 163 3. (optional) handle the wsdl parsing and web service instantiation event through the webservice.Onload handler: // handle the wsdl loading event. Stockservice.Onload = function(wsdl){ wsdlfield.Text = wsdl; } 4. (optional) handle the fault if the wsdl doesn’t load: // if the ws...

  • Page 164

    164 server-side actionscript language reference constructor for the webservice class availability flash media server 2. Usage newwebservice(wsdluri) parameters wsdlurl a string specifying the url of a wsdl url. Returns a webservice object. Description constructor; creates a new webservice object. Yo...

  • Page 165

    Webservice class 165 example the following example displays the fault code in a text field if the wsdl fails to load and the onfault event fires: // prepare the wsdl location: var wsdluri = "http://www.Flash-db.Com/services/ws/companyinfo.Wsdl"; // instantiate the web service object using the wsdl l...

  • Page 166

    166 server-side actionscript language reference example in the following example, the onload event is used to handle the wsdl parsing: // prepare the wsdl location: var wsdluri = "http://www.Flash-db.Com/services/ws/companyinfo.Wsdl"; // instantiate the web service object using the wsdl location: st...

  • Page 167

    Xml class 167 property summary for the xml class property description xml.Attributes an object that contains all the attributes of the specified xml object. Xml.Childnodes read-only; an array of the specified xml object’s children. Each element in the array is a reference to an xml object that repre...

  • Page 168

    168 server-side actionscript language reference method summary for the xml class method description xml.Addrequestheader() adds or changes http headers for post operations. Xml.Appendchild() appends a node to the end of the specified object’s child list. Xml.Clonenode() clones the specified node, an...

  • Page 169

    Xml class 169 event handler summary for the xml class collections summary for the xml class h constructor for the xml class availability flash media server 2. Usage new xml([source]) parameters source a string; the xml text parsed to create the new xml object. Returns a reference to an xml object. E...

  • Page 170

    170 server-side actionscript language reference description constructor; creates a new xml object. You must use the constructor to create an xml object before you call any of the xml class methods. Example the following example creates a new, empty xml object: var my_xml = new xml(); the following e...

  • Page 171

    Xml class 171 description method; adds or changes http request headers (such as content-type or soapaction ) sent with post actions. In the first usage, you pass two strings, headername and headervalue , to the method. In the second usage, you pass an array of strings, alternating header names, and ...

  • Page 172

    172 server-side actionscript language reference description method; appends the specified node to the xml object’s child list. This method operates directly on the node referenced by the childnode parameter; it does not append a copy of the node. If the node to be appended already exists in another ...

  • Page 173

    Xml class 173 xml.Attributes availability flash media server 2. Usage my_xml.Attributes description property; an object that contains all the attributes of the specified xml object. Associative arrays use keys as indexes, not ordinal integer indexes used by regular arrays. In the xml.Attributes asso...

  • Page 174

    174 server-side actionscript language reference xml.Childnodes availability flash media server 2. Usage my_xml.Childnodes description property (read-only); an array of the specified xml object’s children. Each element in the array is a reference to an xml object that represents a child node. This is...

  • Page 175

    Xml class 175 // create another array and use the child nodes to populate it. Var secondarray = rootnode.Childnodes; trace(secondarray); // output: ,, see also xml.Nodetype xml.Clonenode() availability flash media server 2. Usage my_xml.Clonenode(deep) parameters deep a boolean value; if set to true...

  • Page 176

    176 server-side actionscript language reference example the following example shows how to use the xml.Clonenode() method to create a copy of a node: // create a new xml document. Var doc = new xml(); // create a root node. Var rootnode = doc.Createelement("rootnode"); // create three child nodes. V...

  • Page 177

    Xml class 177 // // // // // // // xml.Contenttype availability flash media server 2. Usage my_xml.Contenttype description property; the mime content type that is sent to the server when you call the xml.Send() or xml.Sendandload() method. The default is application/x-www-form-urlencoded, which is t...

  • Page 178

    178 server-side actionscript language reference xml.Createelement() availability flash media server 2. Usage my_xml.Createelement(name) parameters name the tag name of the xml element being created. Returns an xml node; an xml element. Description method; creates a new xml element with the name spec...

  • Page 179

    Xml class 179 xml.Createtextnode() availability flash media server 2. Usage my_xml.Createtextnode(text) parameters text a string; the text used to create the new text node. Returns an xml node. Description method; creates a new xml text node with the specified text. The new node initially has no par...

  • Page 180

    180 server-side actionscript language reference trace(doc); // output (with line breaks added between tags): // // textnode1 // textnode2 // see also xml.Createelement() xml.Doctypedecl availability flash media server 2. Usage my_xml.Doctypedecl description property; specifies information about the ...

  • Page 181

    Xml class 181 xml.Firstchild availability flash media server 2. Usage my_xml.Firstchild description property (read-only); evaluates the specified xml object and references the first child in the parent node’s child list. This property is null if the node does not have children. This property is null...

  • Page 182

    182 server-side actionscript language reference // // see also xml.Appendchild() , xml.Insertbefore() , xml.Removenode() xml.Getbytesloaded() availability flash media server 2. Usage my_xml.Getbytesloaded() parameters none. Returns an integer that indicates the number of bytes loaded. Description me...

  • Page 183

    Xml class 183 returns an integer. Description method; returns the size of the xml document in bytes. Example see the example for xml.Getbytesloaded() on page 182 . See also xml.Getbytesloaded() xml.Getnamespaceforprefix() availability flash media server 2. Usage my_xml.Getnamespaceforprefix(prefix) ...

  • Page 184

    184 server-side actionscript language reference example the following example creates a very simple xml object and outputs the result of a call to getnamespaceforprefix() : function createxml() { var str = "" + "" + "" + "" + ""; return new xml(str).Firstchild; } var xml = createxml(); trace(xml.Get...

  • Page 185

    Xml class 185 example the following example creates a very simple xml object and outputs the result of a call to the getprefixfornamespace() method. The outer xml node, which is represented by the xmldoc variable, defines a namespace uri and assigns it to the exu prefix. Calling the getprefixforname...

  • Page 186

    186 server-side actionscript language reference xml.Haschildnodes() availability flash media server 2. Usage my_xml.Haschildnodes() parameters none. Returns a boolean value. Description method; returns true if the specified xml object has child nodes; false otherwise. Example the following example c...

  • Page 187

    Xml class 187 xml.Ignorewhite availability flash media server 2. Usage my_xml.Ignorewhite xml.Prototype.Ignorewhite parameters boolean a boolean value. Description property; the default setting is false . When set to true , text nodes that contain only white space are discarded during the parsing pr...

  • Page 188

    188 server-side actionscript language reference create a new flash document named flooring.Fla and save it to the same directory as the xml file. Place the following code into the main timeline: // create a new xml object. Var flooring = new xml(); // set the ignorewhite property to true (default va...

  • Page 189

    Xml class 189 xml.Insertbefore() availability flash media server 2. Usage my_xml.Insertbefore(childnode, beforenode) parameters childnode the xmlnode object to be inserted. Beforenode the xmlnode object before the insertion point for the childnode node. Returns nothing. Description method; inserts a...

  • Page 190

    190 server-side actionscript language reference example the following example uses the xml.Lastchild property to iterate through the child nodes of an xmlnode object, starting with the last item in the node’s child list and ending with the first child of the node’s child list: // create a new xml do...

  • Page 191

    Xml class 191 the following example creates a new xml packet and uses the xml.Lastchild property to iterate through the child nodes of the root node: // create a new xml document. Var doc = new xml(""); var rootnode = doc.Firstchild; // use lastchild to iterate through the child nodes of rootnode. F...

  • Page 192

    192 server-side actionscript language reference description method; loads an xml document from the specified url, and replaces the contents of the specified xml object with the downloaded xml data. The url is relative and is called using http. The load process is asynchronous; it does not finish imm...

  • Page 193

    Xml class 193 xml.Loaded availability flash media server 2. Usage my_xml.Loaded description property; a boolean value that is true if the document-loading process initiated by the xml.Load() call completed successfully; false otherwise. Example the following example uses the xml.Loaded property in a...

  • Page 194

    194 server-side actionscript language reference xml.Localname availability flash media server 2. Usage my_xml.Localname description property (read-only); the local name portion of the xml node's name. This is the element name without the namespace prefix. For example, the node >bob@example.Com has t...

  • Page 195

    Xml class 195 see also xml.Nodename , xml.Prefix xml.Namespaceuri availability flash media server 2. Usage my_xml.Namespaceuri description property (read-only); if the xml node has a prefix, namespaceuri is the value of the xmlns declaration for that prefix (the uri), which is typically called the n...

  • Page 196

    196 server-side actionscript language reference the source for the server-side asc file contains the following script (note the comments for the output strings). For tempnode , which represents the w:gettemperature node, the value of namespaceuri is defined in the soap:body tag. For soapbodynode , w...

  • Page 197

    Xml class 197 trace("rootnode node namespaceuri: " + rootnode.Namespaceuri); // output: [empty string] var simplenode = xmldoc.Childnodes[0].Childnodes[0]; trace("simplenode node namespaceuri: " + simplenode.Namespaceuri); // output: ... Http://www.W3.Org/2001/12/soap-envelope var innernode = xmldoc...

  • Page 198

    198 server-side actionscript language reference xml.Nodename availability flash media server 2. Usage my_xml.Nodename description property; a string representing the node name of the xml object. If the xml object is an xml element ( nodetype==1 ), nodename is the name of the tag that represents the ...

  • Page 199

    Xml class 199 the following example creates a new xml packet. If the root node has child nodes, the code loops over each child node to display the name and value of the node. Add the following actionscript to your asc file: var my_xml = new xml("hank rudolph"); if (my_xml.Firstchild.Haschildnodes())...

  • Page 200

    200 server-side actionscript language reference in flash player, the built-in xml class supports only 1 ( element_node ) and 3 ( text_node ). Example the following example creates an element node and a text node and checks the node type of each: // create an xml document. Var doc = new xml(); // cre...

  • Page 201

    Xml class 201 see also xml.Nodevalue xml.Nodevalue availability flash media server 2. Usage my_xml.Nodevalue description property; the node value of the xml object. If the xml object is a text node, the nodetype is 3, and the nodevalue is the text of the node. If the xml object is an xml element ( n...

  • Page 202

    202 server-side actionscript language reference the following example creates and parses an xml packet. The code loops through each child node, and displays the node value using the firstchild property and firstchild.Nodevalue . Var my_xml = new xml("morton good&evil"); trace("using firstchild:"); f...

  • Page 203

    Xml class 203 returns nothing. Description event handler; invoked when xml text has been completely downloaded from the server or when an error occurs when xml text downloads from a server. This handler is invoked before the xml is parsed, and you can use it to call a custom parsing routine instead ...

  • Page 204

    204 server-side actionscript language reference description event handler; invoked when flash media server receives an http status code from the server. This handler lets you capture and act on http status codes. The onhttpstatus handler is invoked before ondata , which triggers calls to onload with...

  • Page 205

    Xml class 205 if(src != undefined) { this.Parsexml(src); this.Loaded = true; this.Onload(true); } else { this.Onload(false); } } myxml.Onload = function(success) { } myxml.Load("http://weblogs.Macromedia.Com/mxna/xml/ rss.Cfm?Query=bymostrecent&languages=1"); see also loadvars.Onhttpstatus , xml.Sen...

  • Page 206

    206 server-side actionscript language reference example the following example includes actionscript for a simple e-commerce storefront application. The sendandload() method transmits an xml element that contains the user’s name and password and uses an xml.Onload handler to process the reply from th...

  • Page 207

    Xml class 207 example the following example creates an xml packet and writes the parent node of the username node to the log file: var my_xml = new xml("morton good&evil"); // the first child is the node. Var rootnode = my_xml.Firstchild; // the first child of the root is the node. Var targetnode = ...

  • Page 208

    208 server-side actionscript language reference description method; parses the xml text specified in the source parameter and populates the specified xml object with the resulting xml tree. Any existing trees in the xml object are discarded. Example the following example creates and parses an xml pa...

  • Page 209

    Xml class 209 example a directory contains a server-side script file and an xml file. The xml file, named "soapsample.Xml" contains the following: san francisco the source for the server-side script file contains the following code (note the comments for the output strings): var xmldoc = new xml(); ...

  • Page 210

    210 server-side actionscript language reference example the following example is an excerpt from the example for the xml.Lastchild property and shows how you can use the xml.Previoussibling property to loop through an xmlnode object’s child nodes: for (var anode = rootnode.Lastchild; anode != null; ...

  • Page 211

    Xml class 211 example the following example creates an xml packet and then deletes the specified xml object and its descendant nodes: var xml_str = " san francisco"; var my_xml = new xml(xml_str); var citynode = my_xml.Firstchild.Firstchild; trace("before xml.Removenode():"+my_xml); citynode.Remov...

  • Page 212

    212 server-side actionscript language reference returns nothing. Description method; encodes the specified xml object into an xml document and sends it to the specified url using the post method in a browser. The flash test environment uses only the get method. Example the following example defines ...

  • Page 213

    Xml class 213 when sendandload() is executed, the xml object property loaded is set to false . When the xml data finishes downloading, the loaded property is set to true if the data successfully loads and the onload event handler is invoked. The xml data is not parsed until it is completely download...

  • Page 214

    214 server-side actionscript language reference xml.Status availability flash media server 2. Usage my_xml.Status description property; automatically sets and returns a numeric value that indicates whether an xml document was successfully parsed into an xml object. The following list contains the nu...

  • Page 215

    Xml class 215 errormessage = "a cdata section was not properly terminated."; break; case -3 : errormessage = "the xml declaration was not properly terminated."; break; case -4 : errormessage = "the doctype declaration was not properly terminated."; break; case -5 : errormessage = "a comment was not ...

  • Page 216

    216 server-side actionscript language reference xml.Tostring() availability flash media server 2. Usage my_xml.Tostring() parameters none. Returns a string. Description method; evaluates the specified xml object, constructs a textual representation of the xml structure, including the node, children,...

  • Page 217

    Xml class 217 xml.Xmldecl availability flash media server 2. Usage my_xml.Xmldecl description property; a string that specifies information about a document’s xml declaration. After the xml document is parsed into an xml object, this property is set to the text of the document’s xml declaration. Thi...

  • Page 218

    218 server-side actionscript language reference xmlsocket class availability flash media server 2. Description the xmlsocket class implements client sockets that let flash media server communicate with a server identified by an ip address or domain name. The xmlsocket class is useful for client-serv...

  • Page 219

    Xmlsocket class 219 method summary for the xmlsocket class event handler summary for the xmlsocket class constructor for the xmlsocket class availability flash communication server mx 1.5. Usage new xmlsocket(streamorflash) parameters streamorflash a string indicating whether this object is an xmlso...

  • Page 220

    220 server-side actionscript language reference for more information about the xmlstreams class, see “xmlstreams class” on page 227 . Example the following example creates an xmlsocket object: var socket = new xmlsocket("flash"); the following example creates an xmlstreams object: var stream = new x...

  • Page 221

    Xmlsocket class 221 xmlsocket.Connect() availability flash media server 2. Usage myxmlsocket.Connect(host, port) parameters host a string; a fully qualified dns domain name or an ip address in the form aaa.Bbb.Ccc.Ddd. You can also specify null to connect to the local host. Port a number; the tcp po...

  • Page 222

    222 server-side actionscript language reference example the following example uses xmlsocket.Connect() to connect to the local host: var socket = new xmlsocket() socket.Onconnect = function (success) { if (success) { trace ("connection succeeded!") } else { trace ("connection failed!") } } if (!Sock...

  • Page 223

    Xmlsocket class 223 example the following example executes a trace() statement if an open connection is closed by the server: var socket = new xmlsocket(); socket.Connect(null, 2000); socket.Onclose = function () { trace("connection to server lost."); } see also xmlsocket.Onconnect xmlsocket.Onconne...

  • Page 224

    224 server-side actionscript language reference example the following example defines a function for the onconnect handler: socket = new xmlsocket(); socket.Onconnect = myonconnect; socket.Connect(null,2000); function myonconnect(success) { if (success) { trace("connection success") } else { trace("...

  • Page 225

    Xmlsocket class 225 example in the following example, the src parameter is a string containing xml text downloaded from the server. The zero (0) byte terminator is not included in the string. Xmlsocket.Prototype.Ondata = function (src) { this.Onxml(new xml(src)); } xmlsocket.Onxml availability flash...

  • Page 226

    226 server-side actionscript language reference the following displaymessage() function is assumed to be a user-defined function that shows the message that the user receives: socket.Onxml = function (doc) { var e = doc.Firstchild; if (e != null && e.Nodename == "message") { displaymessage(e.Attribu...

  • Page 227

    Xmlstreams class 227 see also xmlsocket.Connect() xmlstreams class availability flash media server 2. Description the xmlstreams class is a variation of the xmlsocket class—it has all the same methods, properties, and events, but it transmits and receives data in fragments. To create an xmlstreams o...

  • Page 228

    228 server-side actionscript language reference.

  • Page 229

    229 a appendix a server-side information objects the application, netconnection, and stream classes 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 info...

  • Page 230

    230 server-side information objects application information objects the following table lists the information objects for the application object. Code level meaning application.Script.Error error the actionscript engine has encountered a runtime error. In addition to the standard infoobject properti...

  • Page 231

    Netconnection information objects 231 netconnection information objects the netconnection class has the same information objects as the client-side netconnection class. Code level meaning netconnection.Call.Failed error the netconnection.Call method was not able to invoke the server-side method or c...

  • Page 232

    232 server-side information objects stream information objects the information objects of the stream class are similar to those of the client-side netstream class. Code level meaning netstream.Clear.Success status a recorded stream was deleted successfully. Netstream.Clear.Failed error a recorded st...

  • Page 233

    Stream information objects 233 † this information object also has a details property, which is a string that provides the name of the streams being played. This is useful for multiple plays. The details property shows the name of the stream when switching from one element in the playlist to the next...

  • Page 234

    234 server-side information objects.