Tuesday, July 14, 2009

Sending HTTP GET request in Flash Lite 3.0


To send HTTP GET request in Flash Lite you have two options depending on the type of data you are receiving

Case you want to receive normal plain text
Sample Code

===================================================

var requestHandler:LoadVars = new LoadVars();

requestHandler.load("http://www.google.com",requestHandler,"GET");

requestHandler.onData = function(str:String) {
trace("data reached");
if (str == undefined) {
trace("Error loading content.");
return;
} else
{
trace("can be read.");
//testTxt is a container where text can be displayed
testTxt.text = str;
}
}
===================================================

N.B:
If you tried to print the str in the output window, the str will not be printed, the only way to see that output is to set the content of a container with it.

Case you want to receive XML data

Sample Code

===================================================

var xmlData:XML = new XML();
xmlData.ignoreWhite = true;

xmlData.load("http://rss.news.yahoo.com/rss/entertainment");

xmlData.onLoad = function(sucesso:Boolean):Void {
if (sucesso) {
var firstlist:Array = xmlData.childNodes;
var secondList:Array = firstlist[0].childNodes;
//.......................
//.......................
//....................... so on
}
};

===================================================

No comments:

Post a Comment