Invoking a Server Function from Macromedia Flash


Listing E.14 will call the method sayHelloServer, which was created in the SSAS Client object when the client connected.

Listing E.14 Flash ActionScript for Invoking a Server Function
 nc = new NetConnection(); nc.onStatus = function() {      nc.call("  sayHelloServer  ", new server_ret()); }; nc.connect("rtmp://localhost/myApplication/myInstance"); // handle the method results returned from the server. server_ret = function () {       this.onResult = function(value_ret) {             trace("Message From the Server: "+value_ret);       };       this.onStatus = function() {             trace("Method Failed");       }; }; 

There are two ways to create a client function on the server. Option A (in Listing E.15) creates the function on the unique client instance when it connects.

Listing E.15 Server-Side ActionScript (Option A) for Invoking a Server Function
 application.onConnect = function(clientObject) {       application.acceptConnection(clientObject);       // Define a function for the Client to Call  - send him an object       clientObject.  sayHelloServer  = function() {             // Trace in the App Inspector             trace("The client says How Ya Doin, Bucko.. Got Somthin' for ya!");             // return a string to the Flash Player             return ("FlashCom Server Rocks!");       }; }; 

Shown in Listing E.16, Option B will create a prototype function that all clients can access.

Listing E.16 Server-Side ActionScript (Option B) for Invoking a Server Function
 clientObject.  prototype.sayHelloServer  = function() {       // Trace in the App Inspector       trace("The client says How Ya Doin, Bucko.. Got Somthin' for ya!");       // return a string to the Flash Player       return ("FlashCom Server Rocks!"); }; 


Macromedia Flash Communication Server MX
Macromedia Flash Communication Server MX
ISBN: 0735713332
EAN: 2147483647
Year: 2002
Pages: 200
Authors: Kevin Towes

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net