Danh mục

Flash Builder 4 and Flex 4 Bible- P16

Số trang: 50      Loại file: pdf      Dung lượng: 636.60 KB      Lượt xem: 12      Lượt tải: 0    
tailieu_vip

Hỗ trợ phí lưu trữ khi tải xuống: 19,000 VND Tải xuống file đầy đủ (50 trang) 0
Xem trước 5 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Flash Builder 4 and Flex 4 Bible- P16: When Macromedia first released Flash MX in 2002, the product was branded as the newway to build Rich Internet Applications (known by the acronym RIA). The term wasinvented at Macromedia to describe a new class of applications that would offer thebenefits of being connected to the Internet, including access to various types of Web-based services,but would solve many of the nagging issues that had been inherent in browser-based applicationssince the mid-1990s....
Nội dung trích xuất từ tài liệu:
Flash Builder 4 and Flex 4 Bible- P16 Chapter 23: Working with HTTPService and XML 8. Save and run the application. As shown in Figure 23.9, you should see that the applica- tion automatically retrieves and displays the data upon startup. FIGURE 23.9 Data returned using code generated by Flash Builder Listing 23.2 shows the completed application code. Notice that the use of the generated service and value object classes makes the application code itself very simple.LISTING 23.2A completed application using generated HTTP data connection code continued 721Part III: Working with Data LISTING 23.2 (continued) Declaring and Configuring HTTPService Objects While the new code generation tools are fast and easy to use and generate code that’s adequate for most simple Flex applications, it’s also important to understand how the generated code works. In the next sections of this chapter I describe the HTTPService and CallResponder components and detail how to use them in a data-centric Flex application. You can declare and configure an HTTPService object in either MXML or ActionScript code. For applications that communicate only with a single network resource, the MXML approach might be simpler and easier to implement. In more complex applications that use multiple network resources, ActionScript classes and methods that dynamically generate HTTPService objects as needed can be easier to manage. Creating an HTTPService object The MXML syntax to create an HTTPService object looks like this: As with all Flex components, the object’s id property is used to identify it uniquely in the context of the current application or component. The url property (discussed in detail in the next section) can be set with either a literal String, as in this example, or with a binding expression if you want to be able to switch to a different network resource at runtime.722 Chapter 23: Working with HTTPService and XMLNew FeatureAs with all nonvisual components, an HTTPService object declared in MXML must be wrapped in an element in Flex 4. nNoteThe HTTPService and other RPC classes are declared in the both the MX and the Spark MXML manifests, soyou can use either the mx: or the s: prefix. Flash Builder auto-completes these declarations with the s: prefixby default. n The equivalent ActionScript code looks like this: import mx.rpc.http.HTTPService; private var myService:HTTPService = new HTTPService(“data/contacts.xml”); Alternatively, you can declare the object first and then set its url in a separate statement: private var myService:HTTPService = new HTTPService(); myService.url = “data/contacts.xml”; The Flex framework’s class library has two HTTPService classes. The first, which is imported in the preceding example, is a member of the mx.rpc.http package and is used in ActionScript code. The other version of the HTTPService class is a subclass of the first and is a member of the mx.rpc.http.mxml package. This is the version you use when you instantiate the object with the tag. The versions are nearly identical with only one difference. The MXML version implements an initialized() method that’s designed to be called after the object’s instantiation. When you declare the HTTPService object in MXML, this method is called automatically; you only need to call it yourself if you instantiate this version of the class in ActionScript code.New FeatureIn Flex 3, the showBusyCursor property, which causes an animated cursor to be displayed for the durationof an HTTPService request/response cycle, and the concurrency property, which determines how multi-ple concurrent requests to the same network resource are handled, were declared in the MXML version ofHTTPService. In Flex 4, these have been moved to the superclass, mx.rpc.http.HTTPService, and aretherefore available regardless of how you declare or instantiate the RPC object. nTipActionScript-based declarations of HTTPService should be placed outside of any function declarations, sothat the object is accessible from all functions in the current application or component. n Essential HTTPService properties Whether ...

Tài liệu được xem nhiều: