As part of this process, we are going to take a closer look at one of the classes we used the most in
our exercises: the HTTPService.
HTTPService is used to get data from a server by making an HTTP (Hypertext Protocol) request to a specific
URL and obtaining a response from a server. You can also optionally pass parameters to the URL.
In simple terms, a request is sent to a server via a URL; the server awaits the request and, based on the
URL given, returns data back to the client. When exchanging data with a server, Flex is extremely versatile
and compliant with almost every standard protocol out there.
The HTTPService tag is a neat way to make an HTTP request. As shown in Figure 7-14, we open the
HTTPService tag and give it a unique ID so we can reference it later. Then we have a url property in
which we enter the location of the file we need??”in this case, the myXMLFile.xml file. As you can see,
this can be a full URL or a local file as long as the SWF resides in the same directory as the file we are
requesting. The resultFormat allows us to indicate how we want to deserialize the file we get back
from the server??”in other words, whether we want to treat it as an object, array, XML, FlashVar, text,
or ECMAScript for XML (E4X). For this example, we chose E4X; you will see why in a moment.
Figure 7-14. HTTPService
Finally, the HTTPService executes the request as soon as we call its send() method. In this example,
we call this method at the application??™s creationComplete event.
Pages:
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116