myClient.remoteMethod = function([p1, ..., pN]){}
Invoked when a client or another server calls the NetConnection.call() method. A remoteMethod parameter is passed to NetConnection.call(). The server searches the Client object instance for a method that matches the remoteMethod parameter. If the method is found, it is invoked and the return value is sent back to the result object specified in the call to NetConnection.call().
Flash Communication Server 1
p1, ..., pN Optional parameters passed to the NetConnection.call() method.
The following example creates a method called sum() as a property of the Client object newClient on the server side:
newClient.sum = function(op1, op2){
return op1 + op2;
};
The sum() method can then be called from NetConnection.call() on the client side:
nc = new NetConnection();
nc.connect("rtmp://myServer/myApp");
nc.call("sum", new result(), 20, 50);
function result(){
this.onResult = function (retVal){
output += "sum is " + retVal;
};
this.onStatus = function(errorVal){
output += errorVal.code + " error occurred";
};
}
The sum() method can also be called on the server:
newClient.sum();
The following example creates two functions that you can call from either a client-side or server-side script:
application.onConnect = function(clientObj) {
// The function foo returns 8.
clientObj.foo = function() {return 8;};
// The function bar is defined outside the onConnect call.
clientObj.bar = application.barFunction;
};
// The bar function adds the two values it is given.
application.barFunction = function(v1,v2) {
return (v1 + v2);
};
You can call either of the two functions that were defined in the previous example (foo and bar) by using the following code in a client-side script:
c = new NetConnection();
c.call("foo");
c.call("bar", null, 1, 1);
You can call either of the two functions that were defined in the previous example (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.Success") {
c.call("foo");
c.call("bar", null, 2, 2);
}
};