What is the role of source for an ArrayCollection or XMLListCollection?
Is it used just once - when constructing a new ArrayCollection or XMLListCollection object and is it copied to some internal data structure of that object?
Because nothing is updated when the source Array (or XMLList) is being modified and the documentation confirms it too:
The underlying XMLList for this collection. The XMLListCollection object does not represent any changes that you make directly to the source XMLList object. Always use the XMLListCollection methods to modify the collection.
This property can be used as the source for data binding. When this property is modified, it dispatches the listChanged event.
I'm asking because Flex examples related to dataProviders always use some Array or XMLList as source of data for a data-driven component. And I wonder, if using Array or XMLList is necessary at all - when for example loading data from external PHP-script.
Using collections ArrayCollection
or XMLListCollection
, you can apply sorting or filter to them. In this case source
will return all the elements in original order without applying filter. I often use source
this way. Adding and removing items from collection also modifies original source array.
What about using collections or arrays as data provider, you can use them all in MX lists but Spark lists can only accept IList
's which implemented by collections mentioned above.
The advantage of using collections as data provider is in possibility to apply filters and sorting without modifying of original array. And of course possibility to listen collection's changes.
Using pure Array
or XMLList
in samples, I suppose, is for simplicity and some implementation details of particular client-server interaction.