Nathan Osman
Nathan Osman

Reputation: 73175

Is there a simple ActionScript class that fetches the content from a URL and returns it?

Is there a standard class that simply returns the response received from a URL given a URL?

Looking through the documentation, I found mx.servicetags.HTTPService, but I don't think it's what I'm looking for.

Update: The request is happening inside of a function and therefore that same function has to return the result. In other words, callbacks aren't going to work.

Upvotes: 0

Views: 99

Answers (2)

Amarghosh
Amarghosh

Reputation: 59451

HTTPService is specific to Flex. If you're looking for a pure actionscript-3 solution, use URLLoader with URLRequest.

var ldr:URLLoader = new URLLoader();
ldr.addEventListener(Event.COMPLETE, onLoad);
ldr.load(new URLRequest(url));

function onLoad(e:Event):void
{
  var loadedText:String = URLLoader(e.target).data;
  trace(loadedText);
}

Upvotes: 4

Related Questions