0
votes

I am building a simple AIR app that allows a user to query a backend server (that I didnt make) in the form http://site.com/test?query=xxx and the user adds the xxx part and presses go. The result is some small HTML code with a result. The resulting webpage if I punched in http://site.com/test?query=google.com would look like this:

google.com : search

What I have figured out is how to simply load the URL into a webview but I would much rather take the non-HTML content (in above example: google.com: search) and put it into a textfield where I can control the formatting.

Updated - I was able to get it working with the below

 var url:String = "http://site.com/test?query=xxx";
 var loadit:URLLoader = new URLLoader();     
 loadit.addEventListener(Event.COMPLETE, completeHandler);
 loadit.load(new URLRequest(url));    
 function completeHandler(event:Event):void {    
    myText_txt.htmlText = event.target.data as String;
 }
2

2 Answers

0
votes

Since you wish to avoid a webview, I believe the best course would be to use a HTTPService to send your uri and use an XML object to parse and traverse the result

private var http:HTTPService = new HTTPService();//class handling the connection
private var data:URLVariables = new URLVariables();//where you will place your data to pass

private function sendData(input:String):void{

http.url = "http://www.site.com";
http.method = "POST";
http.addEventListener(ResultEvent.RESULT,onResult)
http.addEventListener(FaultEvent.FAULT,onFailure)

data.query = input;

http.send(data);
}
private function onResult(event:ResultEvent):void{
var result:XML = new XML(event.result.toString());
for each (var entry:XMLList in result){//parse it somehow}
}
private function onFailure(event:FaultEvent):void{//error conditions}

However you may encounter errors depending on the result as I believe HTTPService is not intended for webpages

EDIT: You may be better off using event.message.body on the ResultEvent as that always returns the absolute string rather than a parsed version.

0
votes
var url:String = "http://site.com/test?query=xxx";
var loadit:URLLoader = new URLLoader();     
loadit.addEventListener(Event.COMPLETE, completeHandler);
loadit.load(new URLRequest(url));    
function completeHandler(event:Event):void {    
   myText_txt.htmlText = event.target.data as String;
}