Listing E.14 will call the method sayHelloServer, which was created in the SSAS Client object when the client connected.
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.
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.
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!");
};