A pesky callback/scope problem?
Hello! I am having quite a time dealing with getting data passed around correctly and hope someone will be able to shed some light on the situation. Here is my setup... I have an AS3 project communicating with an FMSv4 which is in turn communicating with a remoting server. The mockup is like so - I am doing it from memory and not copy and paste so ignore any actual programming problems... it is the data scope issue I am trying to resolve 😐
// AS3
var rsp:Responder = new Responder(r_success, r_failure);
connection.call("fms_function", rsp);
function r_success(obj:Object)
{
trace("it worked "+ obj);
}
function r_failure(obj:Object)
{
trace("it failed");
}
// FMS - main.asc - netconnection etc has been correctly defined.
Client.prototype.fms_function = function()
{
mygateway.call("remote_function", remoting_handler());
function remoting_handler()
{
this.onResult(data)
{trace("result received");
return(data); // ( 1 )
}
this.onStatus(data)
{
trace("whoops");
}
}
}
Okay, so that is the setup... as I said before please disregard possible errors in the syntax.. my code traces out correctly showing flow as expected and gets the data from the remoting server correctly. When the client calls the fms_function on the FMS it traces "it worked null", showing the data has not been returned through the method called in my main.asc. My problem is trying to get the data retrieved from the remoting server to return back through fms_function to the client function that called it, at point ( 1 ) above. I have nested it as above hoping the scope would resolve back to fms_function, however this fails. I have tried passing fms_function as a parameter into remoting_handler, but my attempts to pass remoting_handler(this) by reference, for example, failed. I have also tried not using a nested handler, but the data does not get returned through the fms_function method to the client. Using client.call and passing it back that way is not an option. How am I able to get the data from the remoting server to return to the client via fms_function? Any help would be appreciated. I have been trying for quite some time and have come up with a bunch of ways to not resolve my problem.
