Packageas3.collections.fx
Classpublic class ArrayListFx
InheritanceArrayListFx Inheritance ArrayList
ImplementsIArrayListFx

Event dispatching ArrayList.

Dispatchs events after all changes to the list.

The dispatched event is of type FxEvents.COLLECTION_CHANGED and can be distinguished by its event.kind property.

All events of kind ITEM_xxx contain a reference to the affected item as well as an iterator returning either the affected item (add, replace) or its successor (remove) with the first call to getNext().

The iterator returned by the particular collection event does not recognize, whether the collection has been changed during an event dispatcher sequence and may become invalid. So do not change the collection in event handlers and their scope.

Usage example
   package fx.basicusage {
    import as3.collections.fx.ArrayListFx;
    import as3.collections.fx.IArrayListFx;
    import as3.collections.fx.events.ArrayListEvent;
    import as3.collections.fx.events.FxEvents;
    import as3.collections.iterators.IIterator;
   
    import flash.display.Sprite;
   
    public class ArrayListFxExample extends Sprite {
     
     public var list : IArrayListFx;
     
     public function ArrayListFxExample() {
      
      list = new ArrayListFx();
      list.addEventListener(FxEvents.COLLECTION_CHANGED, collectionChanged);
      
      // add - [5,1,3,2,4]
      list.addItem(1);
      list.addItem(2);
      list.addItemAt(1, 3);
      list.addItemAtEnd(4);
      list.addItemAtStart(5); 
      
      // replace - [5,1,3,2,3]
      list.replaceItemAt(4, 3);
      list.replaceItemAt(3, 2); // no event since 2 == 2
   
      // remove - [1]
      list.removeItem(2);
      list.removeItemAt(0);
      list.removeAll(3);
   
      // change source - [1,2,3,4,5]
      list.setArray([1,2,3,4,5]);
   
      // empty list - []
      list.clear();
   
     }
     
     private function collectionChanged(event : ArrayListEvent) : void {
      var item : = event.item;
      var index : = event.index;
      var iterator : IIterator = event.getIterator();
      
      switch (event.kind) {
       case FxEvents.ITEM_ADDED:
        trace ("Added item: " + item + " at index " + index);
        trace ("Added after: " + iterator.getCurrent());
        iterator.getNext(); // returns added item
        trace ("Added before: " + iterator.getNext());
        break;
       case FxEvents.ITEM_REMOVED:
        trace ("Removed " + item + " at index " + index);
        trace ("Removed after: " + iterator.getCurrent());
        trace ("Removed before: " + iterator.getNext());
        break;
       case FxEvents.ITEM_REPLACED:
        trace ("Replaced item: " + item + " at index " + index);
        trace ("Replaced after: " + iterator.getCurrent());
        iterator.getNext(); // returns replaced item
        trace ("Replaced before: " + iterator.getNext());
        break;
       case FxEvents.COLLECTION_REPLACED:
        trace ("Collection replaced");
        break;
       case FxEvents.COLLECTION_EMPTIED:
        trace ("Collection emptied");
        break;
      }
      
      trace ("----------------------");
      trace ("[" + list.toArray() + "]\n");
     }
    }
   }
   
   // Added item: 1 at index 0
   // Added after: undefined
   // Added before: undefined
   // ----------------------
   // [1]
   
   // Added item: 2 at index 1
   // Added after: 1
   // Added before: undefined
   // ----------------------
   // [1,2]
   
   // Added item: 3 at index 1
   // Added after: 1
   // Added before: 2
   // ----------------------
   // [1,3,2]
   
   // Added item: 4 at index 3
   // Added after: 2
   // Added before: undefined
   // ----------------------
   // [1,3,2,4]
   
   // Added item: 5 at index 0
   // Added after: undefined
   // Added before: 1
   // ----------------------
   // [5,1,3,2,4]
   
   // Replaced item: 3 at index 4
   // Replaced after: 2
   // Replaced before: undefined
   // ----------------------
   // [5,1,3,2,3]
   
   // Removed 2 at index 3
   // Removed after: 3
   // Removed before: 3
   // ----------------------
   // [5,1,3,3]
   
   // Removed 3 at index 1
   // Removed after: 1
   // Removed before: 3
   // ----------------------
   // [1,3]
   
   // Removed 3 at index 1
   // Removed after: 1
   // Removed before: undefined
   // ----------------------
   // [1]
   
   // Collection replaced
   // ----------------------
   // [1,2,3,4,5]
   
   // Collection emptied
   // ----------------------
   // []
  



Public Properties
 PropertyDefined by
  array : Array
[read-only]
ArrayListFx
 InheritednumItems : uint
Returns the size of the collection.
ArrayList
Protected Properties
 PropertyDefined by
 Inherited_array : Array
The array.
ArrayList
Public Methods
 MethodDefined by
  
Creates a new ArrayListFx.
ArrayListFx
  
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
ArrayListFx
  
addItem(item:*):Boolean
Adds an item to the list, usually at the end.
ArrayListFx
  
addItemAt(index:uint, item:*):uint
Adds an item at a specific position.
ArrayListFx
 Inherited
addItemAtEnd(item:*):uint
Adds an item at the end of the list.
ArrayList
 Inherited
addItemAtStart(item:*):uint
Adds an item in front of the list.
ArrayList
  
addItemsAt(index:uint, items:Array):uint
Adds an array of items at a specific position.
ArrayListFx
  
clear():void
Removes all items from the collection.
ArrayListFx
 Inherited
countItems(item:*):uint
Returns the number of occurrences of an item.
ArrayList
  
dispatchEvent(event:Event):Boolean
ArrayListFx
 Inherited
getFirstIndexOf(item:*):int
Returns the index of the first occurrence of an item.
ArrayList
 Inherited
Returns the first item of the sequence.
ArrayList
 Inherited
getItemAt(index:uint):*
Returns the item at the specified position.
ArrayList
 Inherited
getIterator(cursor:uint = 0):IIterator
Returns an iterator over the list items starting at the specified position.
ArrayList
 Inherited
Returns the last item of the sequence.
ArrayList
  
hasEventListener(type:String):Boolean
ArrayListFx
 Inherited
hasItem(item:*):Boolean
Tests, if an item is contained by the list.
ArrayList
 Inherited
removeAll(item:*):uint
Removes all occurrences of a particular item from the list.
ArrayList
  
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
ArrayListFx
 Inherited
Removes the first item of the sequence.
ArrayList
 Inherited
removeItem(item:*):Boolean
Removes an item from the list.
ArrayList
  
removeItemAt(index:uint):*
Removes an item at the specified position.
ArrayListFx
  
removeItemsAt(index:uint, numItems:uint):Array
Removes a number of items starting at the specified position.
ArrayListFx
 Inherited
Removes the last item of the sequence.
ArrayList
  
replaceItemAt(index:uint, item:*):Boolean
Replaces the item at the specified position.
ArrayListFx
 Inherited
reverse():void
Reverses the list order.
ArrayList
  
setArray(array:Array):void
Specifies an array to be maintained by the list.
ArrayListFx
 Inherited
sort(comparator:IComparator):void
Sorts the list by the given criterion.
ArrayList
 Inherited
toArray():Array
Returns an array of all items in the order of the particular collection.
ArrayList
  
toString():String
Info
ArrayListFx
  
willTrigger(type:String):Boolean
ArrayListFx
Protected Methods
 MethodDefined by
  
itemRemoved(item:*, index:uint):void
Template method to notify subclasses after an item has been removed.
ArrayListFx
Events
 EventSummaryDefined by
   Event type for all collection events.ArrayListFx
Property detail
arrayproperty
array:Array  [read-only]

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

Implementation
    public function get array():Array
Constructor detail
ArrayListFx()constructor
public function ArrayListFx()

Creates a new ArrayListFx.

Method detail
addEventListener()method
public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):voidParameters
type:String
 
listener:Function
 
useCapture:Boolean (default = false)
 
priority:int (default = 0)
 
useWeakReference:Boolean (default = false)
addItem()method 
public override function addItem(item:*):Boolean

Adds an item to the list, usually at the end.

Parameters
item:* — The item.

Returns
Boolean — true, if the item has been added, else false.
addItemAt()method 
public override function addItemAt(index:uint, item:*):uint

Adds an item at a specific position.

If the given position exceeds the array length, the item will be appended.

Parameters
index:uint — The position of the new item.
 
item:* — The item.

Returns
uint — The index of the just added item.
addItemsAt()method 
public override function addItemsAt(index:uint, items:Array):uint

Adds an array of items at a specific position.

If the given position exceeds the array length, the items will be appended.

Parameters
index:uint — The position of the first new item.
 
items:Array — An array of items to add.

Returns
uint — The index where the items have been added.
clear()method 
public override function clear():void

Removes all items from the collection.

dispatchEvent()method 
public function dispatchEvent(event:Event):BooleanParameters
event:Event

Returns
Boolean
hasEventListener()method 
public function hasEventListener(type:String):BooleanParameters
type:String

Returns
Boolean
itemRemoved()method 
protected override function itemRemoved(item:*, index:uint):void

Template method to notify subclasses after an item has been removed.

Parameters
item:* — The removed item.
 
index:uint — The former index of the removed item.
removeEventListener()method 
public function removeEventListener(type:String, listener:Function, useCapture:Boolean = false):voidParameters
type:String
 
listener:Function
 
useCapture:Boolean (default = false)
removeItemAt()method 
public override function removeItemAt(index:uint):*

Removes an item at the specified position.

Parameters
index:uint — The position of the item to remove.

Returns
* — The removed item or undefined, if there is no item at that position.
removeItemsAt()method 
public override function removeItemsAt(index:uint, numItems:uint):Array

Removes a number of items starting at the specified position.

Parameters
index:uint — The position of the first item to remove.
 
numItems:uint — The number of items to remove.

Returns
Array — An array of all removed items.
replaceItemAt()method 
public override function replaceItemAt(index:uint, item:*):Boolean

Replaces the item at the specified position.

If the item at the position equals the given item or the index is invalid, this method returns false and leaves the list unchanged.

Parameters
index:uint — The position of the item to replace.
 
item:* — The replacing item.

Returns
Boolean — true, if the item at that position has been replaced..
setArray()method 
public override function setArray(array:Array):void

Specifies an array to be maintained by the list.

Already contained elements will be removed.

Parameters
array:Array — The array.
toString()method 
public override function toString():String

Info

Returns
String
willTrigger()method 
public function willTrigger(type:String):BooleanParameters
type:String

Returns
Boolean
Event detail
collectionChangedevent 
Event object type: as3.collections.fx.events.ArrayListEvent
ArrayListEvent.type property = as3.collections.fx.events.FxEvents.COLLECTION_CHANGED

Event type for all collection events.

A collection event always is of the type COLLECTION_CHANGED. The specific change to the collection can be distinguished by examine the event's kind property. The kind of an event can be one of the following:

PropertyValue
kind The kind of change to the collection.
item The affected item.
Not set for DATA_SOURCE_REPLACED and COLLECTION_EMPTIED.
getIterator Returns an iterator pointing to the affected item (add, replace) or to its successor (remove).
Not set for DATA_SOURCE_REPLACED and COLLECTION_EMPTIED.
keyThe key of the affected item.
Only set for map events.
Not set for DATA_SOURCE_REPLACED and COLLECTION_EMPTIED.