Paul Mignard
Paul Mignard

Reputation: 5914

Flex - URLLoader and HTTPService

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?

Upvotes: 9

Views: 7782

Answers (2)

Matt MacLean
Matt MacLean

Reputation: 19648

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

Upvotes: 14

James
James

Reputation: 119

There really is no difference between using the two. Both implementations could be considered "correct".

Upvotes: -3

Related Questions