10.12.2012 Views

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Example 5-17. Main.as (document class)<br />

53 }<br />

54 // populate the ListDisplayField with new book titles<br />

55 for each (var bookTitle:XML in xml..entry.title)<br />

56 {<br />

57 newBookListField.addItem(bookTitle.toString( ));<br />

58 }<br />

59 }<br />

60 }<br />

61 }<br />

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

URLLoader( ) method (line 40) loads this document over the Internet, and calls the<br />

xmlLoaded( ) function when loading is <strong>com</strong>plete. The xmlLoaded( ) method is registered<br />

as a listener function (line 41) because loading data is an asynchronous operation<br />

requiring notification when the process is <strong>com</strong>pleted. It is important that the<br />

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

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

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

ListDisplayField adapter. Figure 5-7 shows the output from the example.<br />

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

202 | Chapter 5: Adapter Pattern

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!