Xml – Flex – URLLoader and HTTPService

actionscript-3apache-flexflashxml

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?

Best Answer

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
));
Related Topic