Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 798
Paul Mignard Avatar asked Nov 10 '08 19:11

Paul Mignard


People also ask

What is the use of urlloader in Java?

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.

Why is urlloader dispatched?

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.

How do I run an example of urlloader from a SWF?

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:

What is the default urlrequest parameter?

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


1 Answers

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
));
like image 63
Matt MacLean Avatar answered Sep 18 '22 21:09

Matt MacLean