ActionScript 3.0 Design Patterns

(Chris Devlin) #1

202 | Chapter 5: Adapter Pattern


The feed URL (http://www.oreillynet.com/pub/feed/29) is specified in line 37. The


URLLoader( )method (line 40) loads this document over the Internet, and calls the


xmlLoaded( )function when loading is complete. ThexmlLoaded( )method is regis-


tered as a listener function (line 41) because loading data is an asynchronous opera-


tion requiring notification when the process is completed. It is important that the


default namespace be set if a namespace is specified in the XML document (lines 50-


53). This enables E4X to do proper validation while parsing the XML document. The


for each statement accesses each book title (lines 55-58) and adds it to the


ListDisplayField adapter. Figure 5-7 shows the output from the example.


53 }

54 // populate the ListDisplayField with new book titles
55 for each (var bookTitle:XML in xml..entry.title)
56 {
57 newBookListField.addItem(bookTitle.toString( ));
58 }
59 }
60 }
61 }

Figure 5-7. The O’Reilly new books list displayed using the ListDisplayField adapter


Example 5-17. Main.as (document class)

Free download pdf