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-15. Main.as (document class) (continued)<br />

}<br />

}<br />

}<br />

shoppingListField.deleteItemAt(3);<br />

addChild(shoppingListField);<br />

This client code will display a text field located at point (20,20) on the stage, showing<br />

Bread, Butter, and Cheese in three separate lines in Arial font size 18. Displaying<br />

lists and deleting list items by location is now especially easy for clients. There is no<br />

need to keep items in a list or traverse this list to delete items. All this is implemented<br />

by the adapter and encapsulated. Note that additional methods to manipulate<br />

the list can be easily added to the adapter class. For example, a method to delete<br />

items by content rather than location, or a method to replace or insert a list item can<br />

be implemented by extending the adapter. We have therefore created a generic class<br />

that is reusable in multiple contexts by converting the interface of an existing class.<br />

Extended Example: Displaying the O’Reilly New Books<br />

List<br />

To further illustrate the utility of the ListDisplayField adapter, we’ll use it to display<br />

the list of new books published by O’Reilly Media, Inc. Because this list changes<br />

often, it makes sense to access the list dynamically using network methods, and display<br />

the book titles using the ListDisplayField adapter.<br />

The new books list is published from the O’Reilly web site as a webfeed. A web feed<br />

is a data format used to publish content that changes frequently. The content publisher<br />

syndicates a web feed, allowing users to subscribe to it.<br />

The O’Reilly new books webfeed, shown in Example 5-16, is published using the<br />

Atom Syndication Format, <strong>com</strong>monly known as Atom. Another <strong>com</strong>mon web feed<br />

format is RSS (the RSS 2.0 acronym stands for Really Simple Syndication). Syndication<br />

formats are specified using XML (Extensible Markup Language), which is a way<br />

to create special-purpose markup languages to describe data.<br />

Example 5-16. Condensed version of new books web feed from O’Reilly showing two book entries<br />

<br />

<br />

O'Reilly Media, Inc. New Books<br />

<br />

Extended Example: Displaying the O’Reilly New Books List | 199

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

Saved successfully!

Ooh no, something went wrong!