Packagemx.collections
Classpublic class ArrayCollection
InheritanceArrayCollection Inheritance ListCollectionView Inheritance flash.utils.Proxy
Implementsflash.utils.IExternalizable

The ArrayCollection class is a wrapper class that exposes an Array as a collection that can be accessed and manipulated using the methods and properties of the ICollectionView or IList interfaces. Operations on a ArrayCollection instance modify the data source; for example, if you use the removeItemAt() method on an ArrayCollection, you remove the item from the underlying Array.

MXML Syntaxexpanded Hide MXML Syntax

The <mx:ArrayCollection> tag inherits all the attributes of its superclass, and adds the following attributes:

  <mx:ArrayCollection
  Properties
  source="null"
  />
  

Default MXML Propertysource


Example
The following code creates a simple ArrayCollection object that accesses and manipulates an array with a single Object element. It retrieves the element using the IList interface getItemAt method and an IViewCursor object that it obtains using the ICollectionView createCursor method.
  var myCollection:ArrayCollection = new ArrayCollection([ { first: 'Matt', last: 'Matthews' } ]);
  var myCursor:IViewCursor = myCollection.createCursor();
  var firstItem:Object = myCollection.getItemAt(0);
  var firstItemFromCursor:Object = myCursor.current;
  if (firstItem == firstItemFromCursor)
        doCelebration();
  



Public Properties
 PropertyDefined by
 InheritedfilterFunction : Function
A function that the view will use to eliminate items that do not match the function's criteria.
ListCollectionView
 Inheritedlength : int
The number of items in this collection.
ListCollectionView
 Inheritedlist : IList
The IList that this collection view wraps.
ListCollectionView
 Inheritedsort : Sort
The Sort that will be applied to the ICollectionView.
ListCollectionView
  source : Array
The source of data in the ArrayCollection.
ArrayCollection
Protected Properties
 PropertyDefined by
 InheritedlocalIndex : Array
When the view is sorted or filtered the localIndex property contains an array of items in the sorted or filtered (ordered, reduced) view, in the sorted order.
ListCollectionView
Public Methods
 MethodDefined by
  
ArrayCollection(source:Array = null)
Constructor.
ArrayCollection
 Inherited
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
ListCollectionView
 Inherited
addItem(item:Object):void
Adds the specified item to the end of the list.
ListCollectionView
 Inherited
addItemAt(item:Object, index:int):void
Adds the item at the specified index.
ListCollectionView
 Inherited
contains(item:Object):Boolean
Returns whether the view contains the specified object.
ListCollectionView
 Inherited
Creates a new IViewCursor that works with this view.
ListCollectionView
 Inherited
Prevents changes to the collection itself and items within the collection from being dispatched by the view.
ListCollectionView
 Inherited
dispatchEvent(event:Event):Boolean
ListCollectionView
 Inherited
Enables auto-updating.
ListCollectionView
 Inherited
getItemAt(index:int, prefetch:int = 0):Object
Gets the item at the specified index.
ListCollectionView
 Inherited
getItemIndex(item:Object):int
Returns the index of the item if it is in the list such that getItemAt(index) == item.
ListCollectionView
 Inherited
hasEventListener(type:String):Boolean
ListCollectionView
 Inherited
initialized(document:Object, id:String):void
Called automatically by the MXML compiler when the ListCollectionView is created using an MXML tag.
ListCollectionView
 Inherited
itemUpdated(item:Object, property:Object = null, oldValue:Object = null, newValue:Object = null):void
Notifies the view that an item has been updated.
ListCollectionView
 Inherited
refresh():Boolean
Applies the sort and filter to the view.
ListCollectionView
 Inherited
removeAll():void
Remove all items from the list.
ListCollectionView
 Inherited
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
ListCollectionView
 Inherited
removeItemAt(index:int):Object
Removes the item at the specified index and returns it.
ListCollectionView
 Inherited
setItemAt(item:Object, index:int):Object
Places the item at the specified index.
ListCollectionView
 Inherited
toArray():Array
Returns an Array that is populated in the same order as the IList implementation.
ListCollectionView
 Inherited
toString():String
Prints the contents of this view to a string and returns it.
ListCollectionView
 Inherited
willTrigger(type:String):Boolean
ListCollectionView
Events
 EventSummaryDefined by
 Inherited Dispatched when the ICollectionView has been updated in some way.ListCollectionView
Property detail
sourceproperty
source:Array  [read-write]

The source of data in the ArrayCollection. The ArrayCollection object does not represent any changes that you make directly to the source array. Always use the ICollectionView or IList methods to modify the collection.

This property can be used as the source for data binding.

Implementation
    public function get source():Array
    public function set source(value:Array):void
Constructor detail
ArrayCollection()constructor
public function ArrayCollection(source:Array = null)

Constructor.

Creates a new ArrayCollection using the specified source array. If no array is specified an empty array will be used.

Parameters
source:Array (default = null)