I use URLLoader to load data into my Flex app (mostly XML) and my buddy who is doing the same thing mostly uses HTTPService. Is there a specific or valid reason to use on over the other?
The URLLoader class downloads data from a URL as text, binary data, or URL-encoded variables. It is useful for downloading text files, XML, or other information to be used in a dynamic, data-driven application. A URLLoader object downloads all of the data from a URL before making it available to code in the applications.
Dispatched if a call to URLLoader.load () attempts to load data from a server outside the security sandbox. Also dispatched if a call to URLLoader.load () attempts to load a SWZ file and the certificate is invalid or the digest string does not match the component.
Note: To run this example, put a file named urlLoaderExample.txt in the same directory as your SWF file. That file should only contain the following line of text: answer=42&question=unknown The example code does the following:
request: URLRequest (default = null) — A URLRequest object specifying the URL to download. If this parameter is omitted, no load operation begins. If specified, the load operation begins immediately (see the load entry for more information).
HTTPService inherits AbstractInvoker which allows you to use tokens and responders which you cannot use with URLLoader. Tokens are good when you need to pass specific variables that are relevant to the request, which you want returned with the response.
Other than that, using URLLoader or HttpService to load xml is the same.
Example:
var token:AsyncToken = httpService.send({someVariable: 123});
token.requestStartTime = getTimer();
token.addResponder(new AsyncResponder(
function (evt:ResultEvent, token:Object):void {
var xml:XML = evt.result as XML;
var startTime = token.requestStartTime;
var runTime = getTimer() - startTime;
Alert.show("Request took " + runTime + " ms");
//handle response here
},
function (info:Object, token:Object):void {
//handle fault here
},
token
));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With