mx.collections

# ArrayList - AS3 Flex

Package | mx.collections
Class | public class ArrayList
Inheritance | ArrayList EventDispatcher Object
Implements | IList, IExternalizable, IPropertyChangeNotifier
Subclasses | Conflicts

Language Version: | ActionScript 3.0

Product Version: | Flex 4

Runtime Versions: | Flash Player 10, AIR 1.5

The ArrayList class is a simple implementation of IList that uses a backing Array as the source of the data. Items in the backing Array can be accessed and manipulated using the methods and properties of the `IList` interface. Operations on an ArrayList instance modify the data source; for example, if you use the `removeItemAt()` method on an ArrayList, you remove the item from the underlying Array. This base class will not throw ItemPendingErrors but it is possible that a subclass might.

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

Default MXML Property `source`

More examples

Setting a data provider in ActionScript

Learn more

About collections and data provider components
Collection events and manual change notification
Hierarchical data objects
Data providers and the uid property

Public Properties
Hide Inherited Public Properties
Show Inherited Public Properties

| Property | Defined By
--- | --- | ---
|  | constructor : Object A reference to the class object or constructor function for a given object instance. | Object
|  | length : int [read-only] Get the number of items in the list. | ArrayList
|  | source : Array The source array for this ArrayList. | ArrayList
|  | uid : String Provides access to the unique id for this list. | ArrayList

Public Methods
Hide Inherited Public Methods
Show Inherited Public Methods

| Method | Defined By
--- | --- | ---
|  | ArrayList(source:Array = null) Construct a new ArrayList using the specified array as its source. | ArrayList
|  | addAll(addList:IList):void Adds a list of items to the current list, placing them at the end of the list in the order they are passed. | ArrayList
|  | addAllAt(addList:IList, index:int):void Adds a list of items to the current list, placing them at the position index passed in to the function. | ArrayList
|  | addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void Registers an event listener object with an EventDispatcher object so that the listener receives notification of an event. | EventDispatcher
|  | addItem(item:Object):void Add the specified item to the end of the list. | ArrayList
|  | addItemAt(item:Object, index:int):void Add the item at the specified index. | ArrayList
|  | dispatchEvent(event:Event):Boolean Dispatches an event into the event flow. | EventDispatcher
|  | getItemAt(index:int, prefetch:int = 0):Object Get the item at the specified index. | ArrayList
|  | getItemIndex(item:Object):int Return the index of the item if it is in the list such that getItemAt(index) == item. | ArrayList
|  | hasEventListener(type:String):Boolean Checks whether the EventDispatcher object has any listeners registered for a specific type of event. | EventDispatcher
|  | hasOwnProperty(name:String):Boolean Indicates whether an object has a specified property defined. | Object
|  | isPrototypeOf(theClass:Object):Boolean Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter. | Object
|  | itemUpdated(item:Object, property:Object = null, oldValue:Object = null, newValue:Object = null):void Notify the view that an item has been updated. | ArrayList
|  | propertyIsEnumerable(name:String):Boolean Indicates whether the specified property exists and is enumerable. | Object
|  | removeAll():void Remove all items from the list. | ArrayList
|  | removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void Removes a listener from the EventDispatcher object. | EventDispatcher
|  | removeItem(item:Object):Boolean Removes the specified item from this list, should it exist. | ArrayList
|  | removeItemAt(index:int):Object Remove the item at the specified index and return it. | ArrayList
|  | setItemAt(item:Object, index:int):Object Place the item at the specified index. | ArrayList
|  | setPropertyIsEnumerable(name:String, isEnum:Boolean = true):void Sets the availability of a dynamic property for loop operations. | Object
|  | toArray():Array Return an Array that is populated in the same order as the IList implementation. | ArrayList
|  | toLocaleString():String Returns the string representation of this object, formatted according to locale-specific conventions. | Object
|  | toString():String [override] Pretty prints the contents of this ArrayList to a string and returns it. | ArrayList
|  | valueOf():Object Returns the primitive value of the specified object. | Object
|  | willTrigger(type:String):Boolean Checks whether an event listener is registered with this EventDispatcher object or any of its ancestors for the specified event type. | EventDispatcher

Protected Methods

| Method | Defined By
--- | --- | ---
|  | itemUpdateHandler(event:PropertyChangeEvent):void Called when any of the contained items in the list dispatch an ObjectChange event. | ArrayList
|  | startTrackUpdates(item:Object):void If the item is an IEventDispatcher, watch it for updates. | ArrayList
|  | stopTrackUpdates(item:Object):void If the item is an IEventDispatcher, stop watching it for updates. | ArrayList

Events
Click for more information on events
Hide Inherited Events
Show Inherited Events

| Event | Summary | Defined By
--- | --- | --- | ---
|  | activate | [broadcast event] Dispatched when the Flash Player or AIR application gains operating system focus and becomes active. | EventDispatcher
|  | collectionChange | Dispatched when the IList has been updated in some way. | ArrayList
|  | deactivate | [broadcast event] Dispatched when the Flash Player or AIR application operating loses system focus and is becoming inactive. | EventDispatcher

Property Detail

### length

property

`length:int` [read-only]

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Get the number of items in the list. An ArrayList should always know its length so it shouldn't return -1, though a subclass may override that behavior.

This property can be used as the source for data binding. When this property is modified, it dispatches the `collectionChange` event.

Implementation
`public function get length():int`

### source

property

`source:Array`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

The source array for this ArrayList. Any changes done through the IList interface will be reflected in the source array. If no source array was supplied the ArrayList will create one internally. Changes made directly to the underlying Array (e.g., calling `theList.source.pop()` will not cause `CollectionEvents` to be dispatched.

Implementation
`public function get source():Array`
`public function set source(value:Array):void`

### uid

property

`uid:String`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Provides access to the unique id for this list.

Implementation
`public function get uid():String`
`public function set uid(value:String):void`
Constructor Detail

### ArrayList

()
Constructor

`public function ArrayList(source:Array = null)`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Construct a new ArrayList using the specified array as its source. If no source is specified an empty array will be used.

Parameters

| `source:Array` (default = `null`)`` — The Array to use as a source for the ArrayList.

Method Detail

### addAll

()
method

`public function addAll(addList:IList):void`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Adds a list of items to the current list, placing them at the end of the list in the order they are passed.

Parameters

| `addList:IList` — The list of items to add to the current list

### addAllAt

()
method

`public function addAllAt(addList:IList, index:int):void`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Adds a list of items to the current list, placing them at the position index passed in to the function. The items are placed at the index location and placed in the order they are recieved.

Parameters

| `addList:IList` — The list of items to add to the current list
| `index:int` — The location of the current list to place the new items.

### addItem

()
method

`public function addItem(item:Object):void`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Add the specified item to the end of the list. Equivalent to addItemAt(item, length);

Parameters

| `item:Object` — the item to add

### addItemAt

()
method

`public function addItemAt(item:Object, index:int):void`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Add the item at the specified index. Any item that was after this index is moved out by one.

Parameters

| `item:Object` — the item to place at the index
| `index:int` — the index at which to place the item

Throws

| `RangeError` — if index is less than 0 or greater than the length

### getItemAt

()
method

`public function getItemAt(index:int, prefetch:int = 0):Object`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Get the item at the specified index.

Parameters

| `index:int` — the index in the list from which to retrieve the item
| `prefetch:int` (default = `0`)`` — int indicating both the direction and amount of items to fetch during the request should the item not be local.

Returns

| `Object` — the item at that index, null if there is none

Throws

| `Error` — if the data for that index needs to be loaded from a remote location
| `RangeError` — if the index < 0 or index >= length

### getItemIndex

()
method

`public function getItemIndex(item:Object):int`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Return the index of the item if it is in the list such that getItemAt(index) == item. Note that in this implementation the search is linear and is therefore O(n).

Parameters

| `item:Object` — the item to find

Returns

| `int` — the index of the item, -1 if the item is not in the list.

### itemUpdated

()
method

`public function itemUpdated(item:Object, property:Object = null, oldValue:Object = null, newValue:Object = null):void`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Notify the view that an item has been updated. This is useful if the contents of the view do not implement `IEventDispatcher`. If a property is specified the view may be able to optimize its notification mechanism. Otherwise it may choose to simply refresh the whole view.

Parameters

| `item:Object` — The item within the view that was updated.
| `property:Object` (default = `null`)`` — A String, QName, or int specifying the property that was updated.
| `oldValue:Object` (default = `null`)`` — The old value of that property. (If property was null, this can be the old value of the item.)
| `newValue:Object` (default = `null`)`` — The new value of that property. (If property was null, there's no need to specify this as the item is assumed to be the new value.)

Related API Elements

mx.events.CollectionEvent
mx.core.IPropertyChangeNotifier
mx.events.PropertyChangeEvent

### itemUpdateHandler

()
method

`protected function itemUpdateHandler(event:PropertyChangeEvent):void`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Called when any of the contained items in the list dispatch an ObjectChange event. Wraps it in a `CollectionEventKind.UPDATE` object.

Parameters

| `event:PropertyChangeEvent` — The event object for the ObjectChange event.

### removeAll

()
method

`public function removeAll():void`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Remove all items from the list.

### removeItem

()
method

`public function removeItem(item:Object):Boolean`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Removes the specified item from this list, should it exist.

Parameters

| `item:Object` — Object reference to the item that should be removed.

Returns

| `Boolean` — Boolean indicating if the item was removed.

### removeItemAt

()
method

`public function removeItemAt(index:int):Object`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Remove the item at the specified index and return it. Any items that were after this index are now one index earlier.

Parameters

| `index:int` — The index from which to remove the item.

Returns

| `Object` — The item that was removed.

Throws

| `RangeError` — if index < 0 or index >= length.

### setItemAt

()
method

`public function setItemAt(item:Object, index:int):Object`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Place the item at the specified index. If an item was already at that index the new item will replace it and it will be returned.

Parameters

| `item:Object` — the new value for the index
| `index:int` — the index at which to place the item

Returns

| `Object` — the item that was replaced, null if none

Throws

| `RangeError` — if index is less than 0 or greater than or equal to length

### startTrackUpdates

()
method

`protected function startTrackUpdates(item:Object):void`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

If the item is an IEventDispatcher, watch it for updates. This method is called by the `addItemAt()` method, and when the source is initially assigned.

Parameters

| `item:Object` — The item passed to the `addItemAt()` method.

### stopTrackUpdates

()
method

`protected function stopTrackUpdates(item:Object):void`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

If the item is an IEventDispatcher, stop watching it for updates. This method is called by the `removeItemAt()` and `removeAll()` methods, and before a new source is assigned.

Parameters

| `item:Object` — The item passed to the `removeItemAt()` method.

### toArray

()
method

`public function toArray():Array`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Return an Array that is populated in the same order as the IList implementation.

Returns

| `Array` — An Array populated in the same order as the IList implementation.

Throws

| `Error` — if the data is not yet completely loaded from a remote location

### toString

()
method

`override public function toString():String`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Pretty prints the contents of this ArrayList to a string and returns it.

Returns

| `String` — A String containing the contents of the ArrayList.

Event Detail

### collectionChange

Event

Event Object Type: `mx.events.CollectionEvent`
property CollectionEvent.type = `mx.events.CollectionEvent.COLLECTION_CHANGE`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Dispatched when the IList has been updated in some way.

The CollectionEvent.COLLECTION_CHANGE constant defines the value of the `type` property of the event object for an event that is dispatched when a collection has changed.

The properties of the event object have the following values. Not all properties are meaningful for all kinds of events. See the detailed property descriptions for more information.

Property | Value
--- | ---
`bubbles` | false
`cancelable` | false
`currentTarget` | The Object that defines the event listener that handles the event. For example, if you use `myButton.addEventListener()` to register an event listener, myButton is the value of the `currentTarget`.
`items` | An Array of objects with information about the items affected by the event. The contents of this field depend on the event kind; for details see the `items` property
`kind` | The kind of event. The valid values are defined in the CollectionEventKind class as constants.
`location` | Location within the target collection of the item(s) specified in the `items` property.
`oldLocation` | the previous location in the collection of the item specified in the `items` property.
`target` | The Object that dispatched the event; it is not always the Object listening for the event. Use the `currentTarget` property to always access the Object listening for the event.
`type` | CollectionEvent.COLLECTION_CHANGE

© 2015 Adobe Systems Incorporated. All rights reserved.
Mon Apr 10 2017, 12:28 PM -07:00