Linear data (aka flat or list-based data) typically represents the attributes (or properties) of an individual entity (item).
In turn, multiple items can be aggregated into a list and stored in an Array. An Array provides a mechanism for storage, manipulation and retrieval of linear data within a Flex application.
Note: Arrays can also store hierarchical data (i.e. objects composed of other objects or simple xml objects) but you'll find linear data to be more common.Other data sets represent nested levels of information (hierarchical data). ActionScript provides two native datatypes for working with hierarchical data – XML and XMLList. The contents of each can be accessed and manipulated as needed utilizing the public API (properties and methods) corresponding to the supporting ActionScript class – XML or XMLList.
XML was designed to support the transport, storage and description of hierarchical data using custom markup. The XML class contains methods and properties for working with a single, well-formed XML document.
As one might guess, an XMLList is simply a list of XML objects. Looking closely at the methods of the XML class, you’ll notice that many operations potentially result in a match against multiple XML nodes (i.e. attributes(), children(), descendants(), etc). With each matching node representing the format of a well-formed XML document, it makes sense to provide a class designed to hold one or more XML objects. That class is the XMLList class.
Note: XML and XMLList classes support E4X operations that may also return a list of XML objects (XMLList). This includes shorthand operations such as (.) or (..) used for retrieving children or descendant nodes respectively or predicate filtering.As a Flex developer, your intent, most likely, is to eventually render some, if not all, of your data on the screen. Whether your data is linear or hierarchical in nature, Flex provides the following “data provider” components suited for the task at hand:
- List-based controls (DataGrid, List, TileList and HorizontalList) for linear or flat data structures (Arrays)
- Trees and menu-based controls (Tree, Menu, MenuBar, PopUpMenuButton) for hierarchical data structures (XML or XMLList)
At first glance, this appears to be an acceptable use of data binding. However, using raw data objects (Array, XML and XMLList) as a data provider for a UI control is not considered a best practice.
Instead, it is recommended that collections are used in place of raw data objects for the following reasons:
- Changes to the data stored in a collection are immediately reflected in the UI control
- Collections provide a "view" of the underlying data that can be sorted or filtered
XMLListCollectionSimilar to an ArrayCollection, XMLListCollection extends the ListCollectionView class which implements the ICollectionView and IList interfaces. 3 members of the ICollectionView interface play an integral role in the implementing class' ability to support data binding:
- 2 methods: addEventListener() & dispatchEvent()
- 1 event: collectionChange
For a more detailed look at the guts of data binding, check out Michael Labriola's presentation entitled Diving in the Data Binding WatersTo create an XMLListCollection, 3 techniques are available:
After being "wrapped" by an XMLListCollection, the majority of the XMLList methods are still available including (but not limited to):
Note: E4X shorthand operations also apply to an XMLListCollectionBut now your plain old hierarchical data storage container (XMLList) has been infused with new powers including data binding (as mentioned previously) and new properties / methods.
- refresh (for use with filterfunction and sort properties)
Note: These are the same properties and methods employed by an ArrayCollection. Sharing the same super class (ListViewCollection), ArrayCollection and XMLListCollection behave in a very similar manner, however, it is typically the UI control that will dictate the type of collection required as a data provider. Remember, list-based UI controls (DataGrid, List, TileList and HorizontalList) require linear (or flat) data structures (ArrayCollection) while tree or menu-based controls (Tree, Menu, MenuBar, PopUpMenuButton) require hierarchical data structures (XMLListCollection).In addition to the enhanced API provided by a collection, wrapping an XMLList inside an XMLListCollection provides 2 very powerful features:
View Sorting & Filtering an XMLListCollection Example