Chapter 12. Collections

Collections are powerful extensions to ActionScript’s indexed array component, the core ActionScript Array. Collections add functionality for sorting the contents of an array, maintaining a read position within an array, and creating views that can show a sorted version of the array. Collections also can notify event listeners that the data they contain has been changed, as well as performing custom logic on items added to the source array. It is this capability of the collection to notify listeners of data changes that allows data binding, and it is the collection’s capability to sort its content that allows ListBase-based components to sort and filter their contents. Collections are an integral part of working with both data-driven controls and server-side services returned from a database.

The three most commonly used types of collections are ArrayCollection, ArrayList, and XMLListCollection. ArrayCollection and ArrayList both wrap an Array element and provide convenient methods for adding and removing items by implementing the IList interface. By extending the ListCollectionView class, which implements the ICollectionView interface, ArrayCollection also provides the ability to create a cursor enabling the last read position in the Array to be stored easily. The XMLListCollection wraps an XML object and provides similar functionality: access to objects via an index, convenience methods for adding new objects, and cursor functionality. The XMLListCollection ...

Get Flex 4 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.