Christopher
Christopher

Reputation: 83

GET request Flex / Actionscript 3

Struggling to find any documentation to do a simple GET request to a URL to return JSON in Actionscript / Flex.

Anyone know

Upvotes: 0

Views: 63

Answers (1)

Chris
Chris

Reputation: 1174

Use the URLLoader API.

var myJSON :Object; //listing as per "key:" with "value"
var str_JSON: String = ""; //if you need text String not data Object

var siteloader :URLLoader = new URLLoader( new URLRequest( your_URL ) );

siteloader.addEventListener(Event.COMPLETE, whenSiteLoaded);

function whenSiteLoaded( evt :Event ) :void 
{
  myJSON = JSON.parse(evt.target.data); //get into Object
  str_JSON = evt.target.data; //get into String
  //... any other code
}

You should add to the above the listeners for error conditions (eg: a "file not found" situation)

Upvotes: 2

Related Questions