views:

53

answers:

0

Hi there,

atm i'm trying to create a AMF request to a rails backend. I allready successfuly implemented the AMF communication, but i still got some problems with the custom functions i'm using.

I created a function to request the server if a property in my SQL DB exists, the server return a boolean. In my flexapp the function looks like this:

//Public Class Extends SUPER CLASS
 public function isProperty(PropertyValue:String):Boolean
 {
  var result:Boolean;   
  this.addEventListener(ResultEvent.RESULT, function(event:ResultEvent):void
   {
    switch (event.result)
    {
     case "true":
          result = true;
     break;
     case "false":
      result = false;
     break;
    }
   })
  this.is_Property(PropertyValue);
  return result;
 }


// SUPER CLASS
 public function is_Property(PropertyValue:Object) : mx.rpc.AsyncToken
 {
  var _internal_operation:mx.rpc.AbstractOperation = _serviceControl.getOperation("is_Property");
  var _internal_token:mx.rpc.AsyncToken = _internal_operation.send(PropertyValue) ;

  return _internal_token;
 }   

you might be wondering why i'm using two functions, thats because the second one is auto-genereted by a script which overwrites the class, the public class is where i'm creating methods which i'm calling from whereever i need them. I first was thinking about overriding the functions, but that dosn't work since the AMF objects i get returned from rails are all initialized as "object" and i can't override the auto-generated functions with different return or input types.

thats why i'm creating different-named functions, doing all the work and finaly calling the request AFM functions related to them.

however, as you might see this way that can't work. Everytime i call the isProperty() function i get a "false" returned since the listener was not activated yet since the ResultEvent.RESULT didn't happen yet since it takes some time till the server responses - so the function just returns the result which is not declared yet and therefore false by default.

what i would need is to get the return falue inside the eventhandler so when calling the function isProperty() the return value is returned from the eventlistener, but that dosn't work of course.

is there a solution for something like that? I'm sure there must be a coding convention which i don't know for handling AMF requests. I know that i can return strings from the server and handle them in one big event handler, but i dont want to do that - i want functions telling the server what to do and getting a boolean if it successed or failed.

so what i need is a function that i can call from everywhere and that returns the result of the AMF request.