Danh mục

Flash Builder 4 and Flex 4 Bible- P17

Số trang: 50      Loại file: pdf      Dung lượng: 822.68 KB      Lượt xem: 21      Lượt tải: 0    
Thư viện của tui

Hỗ trợ phí lưu trữ khi tải xuống: 14,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- P17: 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- P17 Chapter 24: Managing XML with E4X If you want to identify namespaces by their URI, use the ActionScript’s namespace keyword to create a namespace object by the URI: private namespace train = “http://www.bardotech.com/train”; private namespace plane = «http://www.bardotech.com/airplane»; private namespace car = “http://www.bardotech.com/automobile”; Alternatively, if you want to identify namespaces by their prefixes as assigned in the XML struc- ture, create variables typed as the Namespace class. Assign each namespace by calling the XML object’s namespace() method and passing the selected namespace prefix: private var train:Namespace = xTravel.namespace(“train”); private var plane:Namespace = xTravel.namespace(“plane”); private var car:Namespace = xTravel.namespace(“car”);NoteThe Namespace class is a top-level Flash Player class, meaning that it isn’t a member of any particular pack-age and can be used without requiring an import statement. nTipNotice that the names of the ActionScript namespace objects match the namespace prefixes in the XML con-tent. This isn’t technically necessary; as long as the namespace Uniform Resource Identifier (URI) or prefixmatch, XML elements will be identified correctly. But consistency between data and code notation certainlydoesn’t hurt. n After the namespace objects have been declared, you can use them as element and attribute pre- fixes in E4X expressions. The namespace object’s name is separated from the element or attribute name with the :: operator to qualify the node as being a member of the selected namespace. The following code extracts the element that’s qualified with the plane namespace: traveltime = xTravel.journey.plane::traveltime; The application in Listing 24.6 declares an XML structure and then enables the user to indicate which of the three values she wants to see. LISTING 24.6 Using XML namespaces in E4X continued 771Part III: Working with Data LISTING 24.6 (continued) @namespace s “library://ns.adobe.com/flex/spark”; @namespace mx “library://ns.adobe.com/flex/mx”; s|RadioButton { font-size:12; font-weight:bold; } 8 hours 1 hour 3 days private namespace train = “http://www.bardotech.com/train”; private namespace plane = “http://www.bardotech.com/airplane”; private namespace car = “http://www.bardotech.com/automobile”; private function getTravelTime():void { var vehicle:String = vehicleGroup.selectedValue as String; switch (vehicle) { case “plane”: travelTime = xTravel.journey.plane::traveltime; break; case “train”: travelTime = xTravel.journey.train::traveltime; break; case “car”: travelTime = xTravel.journey.car::traveltime; } }772 Chapter 24: Managing XML with E4X ]]> On the WebThe code in Listing 24.6 is available in the Web site files as E4XWithNamespaces.mxml in the default pack-age in the src folder of the chapter24 project. n Figure 24.2 shows the resulting application, displaying the results of an E4X expression with namespaces to the user. FIGURE 24.2An application using E4X with namespaces 773Part III: Working with Data Summary In this chapter, I described how to use E4X to parse and modify data stored in XML objects in Flex application memory at runtime. You learned the following: l E4X stands for EcmaScript for XML. l E4X is a standard of Ecma International that is implemented in ActionScript 3 and in certain other languages and platforms. l E4X enables you to parse, extract, and modify XML-based data at runtime with simple, concise expressions. l E4X is a part of the compiled ActionScript language and is ...

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