Im trying to make a HTTP Request in Adobe Flex (Actionscript) as follows:
var p:PersonSearchController = new PersonSearchController();
showAlertDialog();
p.search(sc);
alert.cancel();
navigator.pushView(views.PersonSearchResults, +p.getResp());
So basically, before the search we get a “Searching…” AlertDialog box, once the search is complete, the dialog box disappears and the results screen is pushed onto the screen…
Here is the search method:
function search{
var requestSender:URLLoader= new URLLoader();
dispatcher.addEventListener(Event.COMPLETE, completeHandler);
var urlRequest :URLRequest = new URLRequest("http://airpoint05:8888/MPS2/PersonSearch");
var msg:String = "blah";
/* Setup HTTP Request */
urlRequest.data = msg;
urlRequest.contentType = "application/x-www-form-urlencoded";
urlRequest.method = URLRequestMethod.POST;
requestSender.load(urlRequest);
}
And here is the completeHandler function:
/* URL has completed and got a response */
private function completeHandler(event:Event):void
{
var response:URLLoader = URLLoader(event.target);
this.res = URLLoader(event.target).data;
trace(this.res);
response.close();
}
When this line is called: navigator.pushView(views.PersonSearchResults, +p.getResp());
p.getResp() is nothing as the response hasn’t came back yet. I want the program to basically block until the HTTPResponse is received so I can process the results. At the moment the Popup appear and disappears quickly, and in the background the search goes off and makes the request… I get the response but only after the results screen has been pushed out. How can I make the popup block until we have a HTTPresponse?
Thanks
Phil
Don’t use URLLoader for this, use HTTPService: