Skip to main content
Participant
August 28, 2013
Question

Waiting for a response from HTTPService

  • August 28, 2013
  • 0 replies
  • 317 views

HI

I'm writing a procedure in flash builder 4.6.

To read the tables from the DB, use some functions in a script implemetate

  as, board using HTTPService.

When I make a call I would like that after the send (), actionscript

waiting for the return of the response, before moving to education

next.

how can you do?

my code:

<mx:Application ...>

.....

RestManager.executeGetRestMethod("conversation/start",null);  // Call HTTPService (RestManager.as)

....

RestManager.as

                    public static function executeGetRestMethod (servicePath:String, parameters:Object) {

                              executeRestMethod(servicePath, parameters, 'GET',responseHandler);    

                    }

               

        public static function executeRestMethod (servicePath:String, parameters:Object, httpMethod:String, handlerFunction:Function):void {

       

                           var restService:HTTPService = new HTTPService();

 

                              restService.method = httpMethod;

                              restService.url = getRestBaseUrl() + servicePath;

                              restService.addEventListener(ResultEvent.RESULT, handlerFunction);  // Function for decoding response

                              restService.addEventListener(FaultEvent.FAULT, errorHandler);

 

                              responseHandlerExecuted=false;

 

                              PhiLogger.log("REST Manager", "Operation: " + servicePath+ " ("+httpMethod+")", "Requested");

                              if (parameters != null)

                                        restService.send(parameters);

                              else

                                        restService.send();

 

        }

      

        private static function responseHandler (event:ResultEvent):void {

                  //var event:ResultEvent;

                  response = JSON.decode(event.result.toString());

                  //Alert.show("cid (da restmanager): "+response);

                  PhiLogger.log("REST Manager", "Operation: response ", "Requested");

                  responseHandlerExecuted=true;

        }

This topic has been closed for replies.