ActionScript 3.0 Design Patterns

(Chris Devlin) #1
Extended Example: Displaying the O’Reilly New Books List | 199

This client code will display a text field located at point (20,20) on the stage, show-


ing Bread, Butter, and Cheese in three separate lines in Arial font size 18. Displaying


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


need to keep items in a list or traverse this list to delete items. All this is imple-


mented by the adapter and encapsulated. Note that additional methods to manipu-


late the list can be easily added to the adapter class. For example, a method to delete


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


be implemented by extending the adapter. We have therefore created a generic class


that is reusable in multiple contexts by converting the interface of an existing class.


Extended Example: Displaying the O’Reilly New Books List


To further illustrate the utility of theListDisplayFieldadapter, we’ll use it to dis-


play the list of new books published by O’Reilly Media, Inc. Because this list changes


often, it makes sense to access the list dynamically using network methods, and dis-


play the book titles using theListDisplayField adapter.


The new books list is published from the O’Reilly web site as awe bfeed. A web feed


is a data format used to publish content that changes frequently. The content pub-


lishersyndicates a web feed, allowing users tosubscribe to it.


The O’Reilly new bookswe bfeed,shown in Example 5-16, is published using the


Atom Syndication Format, commonly known asAtom. Another common web feed


format is RSS (the RSS 2.0 acronym stands for Really Simple Syndication). Syndica-


tion formats are specified using XML (Extensible Markup Language), which is a way


to create special-purpose markup languages to describe data.


shoppingListField.deleteItemAt(3);


addChild(shoppingListField);
}
}
}


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


<?xml version='1.0' encoding='utf-8'?>


<feed xmlns='http://www.w3.org/2005/Atom'
xmlns:itunes='http://www.itunes.com/dtds/podcast-1.0.dtd'
xml:lang='en-US'>


O'Reilly Media, Inc. New Books
hreflang="en" title="O'Reilly Media, Inc. New Books" />

Example 5-15. Main.as (document class) (continued)

Free download pdf