Groups | Blog | Home
all groups > macromedia flash flashcom > september 2005 >

macromedia flash flashcom : Reurning a value from FCS???


gjiroux
9/26/2005 10:31:24 AM
I'm trying to find a way to do something very simple... I want the client swf
to trigger a function on the FCS and return a value. Now, I'm not a stupid guy,
but everywhere I've looked I get examples that make no sense...

I think I've found 2 key ingredients... netConnection.call and client.call...
but no real clear way of understanding how they work

I would assume that you from the client you:
thisvariable = nc.call(functionname);

and on the server in the main.asc you:

function functionname(){
return somevalue;
}

but there seems to be some need for:
Client.call(functionInClientSWF, "argumentvalue")

Can anyone give me an example of from a SWF client, calling a function on the
FCS that returns a value to the client... say the application.userList.length

PLEASE HELP!!!


jadedchron
9/27/2005 1:17:08 AM
I would imagine you'd do something like:

variable = nc.call(function, item) for the client-side

function fname(item){
return item;
}

LA Flash Guy
9/30/2005 11:33:22 AM
//client side
var client_nc = new NetConnection();
client_nc.connect();
var responder = new Object();
responder.onResult = function(txt) {
myTrace(txt);
};
//where "someFunction" is the name of a function in your main.asc file
//return will come back through your responder object
client_nc.call("someFunction", responder);

//server side in your main.asc file
application.onConnect = function(newClient) {
//here's your function
newClient.someFunction = function() {
return "Hello World " ;
};
}

Hope that helps.
JayCharles
10/4/2005 12:00:00 AM
in your main.asc

Client.Protype.SomeFunctionName = function(incomingVar1, incomingVar2){
// execute code here
someReturnVar = someValue;
return SomeReturnVar;
}

in your .swf (I'm assuming you've alredy made the netconnection

var responder = new Object();
responder.onResult = function(returnObj) {
trace(returnObj);
};
nameOfYourNc.call("SomeFunctionName", responder, varToSend1, varToSend2);

HTH



jadedchron
10/4/2005 12:26:15 AM
Originally posted by: LA Flash Guy
//client side
var client_nc = new NetConnection();
client_nc.connect();
var responder = new Object();
responder.onResult = function(txt) {
myTrace(txt);
};
//where "someFunction" is the name of a function in your main.asc file
//return will come back through your responder object
client_nc.call("someFunction", responder);

//server side in your main.asc file
application.onConnect = function(newClient) {
//here's your function
newClient.someFunction = function() {
return "Hello World " ;
};
}

Hope that helps.

I for some reason could not get this to work. Does the server side HAVE to be
in a main.asc file? IE can I use:

/server side in your main.asc file
application.onConnect = function(newClient) {
//here's your function
newClient.someFunction = function() {
return "Hello World " ;

Inside of my regular actionscript of the server swf file?

Thanks for your response, Jack.


jadedchron
10/6/2005 12:00:00 AM
Originally posted by: JayCharles
in your main.asc

Client.Prototype.SomeFunctionName = function(incomingVar1, incomingVar2){
// execute code here
someReturnVar = someValue;
return SomeReturnVar;
}

in your .swf (I'm assuming you've alredy made the netconnection and waited for
your onStatus event so you know you're connected)

var responder = new Object();
responder.onResult = function(returnObj) {
trace(returnObj);
};
nameOfYourNc.call("SomeFunctionName", responder, varToSend1, varToSend2);


it's the Client.Prototype that's important. Without associating the function
with the client , FCS doesn't seem to know who to return the data to.

To answer your other question, it doesn't have to be in the main.asc. you can
have it in a separate asc file (in your application directory) and use

load("myASCFileName.asc);

at the top of your main.asc... but yes... it has to be in your SSAS somewhere.
If the client is holding the code, FCS won't have it, and you can't call a
function that doesn't exist on the server.

HTH





Jay/HTH, thanks a lot for responding. When I try to emulate this I receive
"[Object object]" instead of the actual variable. Am I doing something wrong or
do I have to process what was returned even further?

Here's what I have in the client swf:

client_nc = new NetConnection();
client_nc.connect ("rtmp:/chat");
client_nc.onStatus = function(infoObject) {

if (infoObject.code == "NetConnection.Connect.Success") {

//trace("connected");
msg_txt.text = "Connected...";

var responder = new Object();
responder.onResult = function(returnObj) {
//trace(returnObj);
msg_txt.text = msg_txt.text + " returnObj = " + returnObj;
};
client_nc.call("SomeFunctionName", responder, winterfresh);
//trace("This is the responder:");
//trace(responder);
msg_txt.text = msg_txt.text +" This is the responder: " + responder;
}

if (infoObject.code == "NetConnection.Connect.Failed") {
trace("Connection failed.");
}
}


stop();



And for the main.asc file:


Client.Prototype.SomeFunctionName = function(winterfresh){
// execute code here
winterfresh = "is good!";
return winterfresh;
}



Did I mess up the variable when passing them? Thank for any help!
AddThis Social Bookmark Button