View comments | RSS feed

NetConnection.call()

Availability

Usage

call(remoteMethod, resultObject | null [, p1,...,pN])

Parameters

Returns

Nothing.

Description

Method; invokes a command or method on the server. You must create a server-side function to define this method.

Example

The following function checks for a message, sends it, then clears the local string.

function mySend(){
    if (length(msg) > 0) {
        my_nc.call("message", null, msg);
    }
    msg = "";
}

Comments


No screen name said on Dec 12, 2005 at 6:17 AM :
how to declare server side method to call from client?
thanx.
masteryoda said on Aug 16, 2006 at 5:36 PM :
how do you define the resultObjecct?
normanhua said on Dec 3, 2006 at 12:27 PM :
theClient.message=function(){}

theClient is a client object.
tech_writer_00 said on Jan 28, 2007 at 9:14 PM :
The server-side method must have the same name as the first parameter in myNetConnection.call() and it must be defined on the server-side Client object.
tech_writer_00 said on Jan 28, 2007 at 9:33 PM :
The server-side method must be defined on the Client object in the main.asc file.

When a client connects to FMS, FMS passes a reference to the client to application.onConnect(clientObject).
You can define the server-side method in the application.onConnect handler:

application.onConnect = function(clientObject){
// insert code here to conditionally reject the connection
// for example, if there are too many users

// define methods to be called by client
clientObject.remoteMethod = function(){
// insert code here, include a return value
}

application.acceptConnect(clientObject)
}

On the client side:
nc.call("remoteMethod", resultObject);

//create a result object that defines an onResult() method that accepts one parameter.

var resultObject = new Object();
resultObject.onResult = function(returnValue){
// return some value
}
MacOnFlash said on Mar 15, 2007 at 10:27 AM :
application.onConnect = function(newClient)
{
this.acceptConnection(newClient); // must accept first
newClient.someMethod(); // newClient has all of Client proto methods
}
Client.prototype.someMethod = function()
{
var method = "clientNCMethod";
var handler = this; // handler = obj with .onResult && onFault methods for response handling
this.broadcast(method,handler,arg1,arg2,arg3);
}
Client.prototype.broadcast = function()
{
// this will broadcast
this.call.apply(this,arguments);
}
Client.prototype.onResult = function(info)
{
trace(":: Client :: onResult :: "+info);
if(typeof(info) == "object") for(var i in info) trace("\t"+i+" = "+info[i])
}
Client.prototype.onFault = function(result)
{
trace(":: Client :: onResult :: "+result);
if(typeof(info) == "object") for(var i in info) trace("\t"+i+" = "+info[i])
}

... this assumes in 'flash' or otherwise, you have ...

var nc = new NetConnection;
nc.onFault = function(info)
{
// error executing the serverside method
trace(":: netconnection :: onFault :: info = "+info);
if(typeof(info) == "object") for(var i in info) trace("\t"+i+" = "+info[i])
}
nc.onResult = function(info)
{
// serverside method executed
trace(":: netconnection :: onFault :: info = "+info);
if(typeof(info) == "object") for(var i in info) trace("\t"+i+" = "+info[i])
}
nc.clientNCMethod = function()
{
trace(":: netconnection :: clientNCMethod :: "+arguments);
return { code:"My.Event.Code", detail:"did stuff" }
}
nc.connect(your_app_uri)
jonplackett said on Aug 21, 2008 at 5:06 AM :
this all seems very complicated. i took this from the serverside doc and it
works the other way around too and it's much simpler.

nc.call("serverFunctionName", new rHandler);

rHandler = function() {
this.onResult = function(res){
trace(res)
}
this.onStatus = function(info){
trace("failed and got:" + info.code);
}
};
No screen name said on Nov 19, 2008 at 8:11 PM :
How about something like this:

this.shObject = SharedObject.getRemote("myobject", this.ncConnection.uri, false);

this.shObject.newMessage = function() {
// whatever my function does
};



ncConnection.call("newMessage", resultObject);


So I'm creating a SharedObject with a "newMessage" method. Then I'm using NetConnection to call "newMessage" on the SharedObject. Would that work?
tech_writer_00 said on Nov 21, 2008 at 1:33 PM :
No, the function must be defined on the Client object in Server-Side ActionScript.

------------------
This is not the most recent version of this document. Please check the most recent version here:
http://livedocs.adobe.com/flashmediaserver/3.0/hpdocs/00000164.html#228724
tech_writer_00 said on Nov 21, 2008 at 1:35 PM :
No, the function must be defined on the Client object in a server-side script.

Please see the latest version of this doc:
http://livedocs.adobe.com/flashmediaserver/3.0/hpdocs/help.html?content=00000164.html#228724

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/fms/2/docs/00000571.html