| Package | as3.collections.fx |
| Class | public class ArrayListFx |
| Inheritance | ArrayListFx ArrayList |
| Implements | IArrayListFx |
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
// ----------------------
// []
| Property | Defined by | ||
|---|---|---|---|
| array : Array [read-only]
| ArrayListFx | ||
![]() | numItems : uint
Returns the size of the collection.
| ArrayList | |
| Method | Defined 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 | ||
![]() |
addItemAtEnd(item:*):uint
Adds an item at the end of the list.
| ArrayList | |
![]() |
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 | ||
![]() |
countItems(item:*):uint
Returns the number of occurrences of an item.
| ArrayList | |
|
dispatchEvent(event:Event):Boolean
| ArrayListFx | ||
![]() |
getFirstIndexOf(item:*):int
Returns the index of the first occurrence of an item.
| ArrayList | |
![]() |
getFirstItem():*
Returns the first item of the sequence.
| ArrayList | |
![]() |
getItemAt(index:uint):*
Returns the item at the specified position.
| ArrayList | |
![]() |
getIterator(cursor:uint = 0):IIterator
Returns an iterator over the list items starting at the specified position.
| ArrayList | |
![]() |
getLastItem():*
Returns the last item of the sequence.
| ArrayList | |
|
hasEventListener(type:String):Boolean
| ArrayListFx | ||
![]() |
hasItem(item:*):Boolean
Tests, if an item is contained by the list.
| ArrayList | |
![]() |
removeAll(item:*):uint
Removes all occurrences of a particular item from the list.
| ArrayList | |
|
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
| ArrayListFx | ||
![]() |
removeFirstItem():*
Removes the first item of the sequence.
| ArrayList | |
![]() |
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 | ||
![]() |
removeLastItem():*
Removes the last item of the sequence.
| ArrayList | |
|
replaceItemAt(index:uint, item:*):Boolean
Replaces the item at the specified position.
| ArrayListFx | ||
![]() |
reverse():void
Reverses the list order.
| ArrayList | |
|
setArray(array:Array):void
Specifies an array to be maintained by the list.
| ArrayListFx | ||
![]() |
sort(comparator:IComparator):void
Sorts the list by the given criterion.
| ArrayList | |
![]() |
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 | ||
| Method | Defined by | ||
|---|---|---|---|
|
itemRemoved(item:*, index:uint):void
Template method to notify subclasses after an item has been removed.
| ArrayListFx | ||
| Event | Summary | Defined by | ||
|---|---|---|---|---|
| Event type for all collection events. | ArrayListFx | |||
| array | property |
array:Array [read-only]
This property can be used as the source for data binding.
Implementation public function get array():Array
| ArrayListFx | () | constructor |
public function ArrayListFx()Creates a new ArrayListFx.
| 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:*):BooleanAdds an item to the list, usually at the end.
Parametersitem:* — The item.
|
Boolean — true, if the item has been added, else false.
|
| addItemAt | () | method |
public override function addItemAt(index:uint, item:*):uintAdds an item at a specific position.
If the given position exceeds the array length, the item will be appended.
Parametersindex:uint — The position of the new item.
|
|
item:* — The item.
|
uint — The index of the just added item.
|
| addItemsAt | () | method |
public override function addItemsAt(index:uint, items:Array):uintAdds an array of items at a specific position.
If the given position exceeds the array length, the items will be appended.
Parametersindex:uint — The position of the first new item.
|
|
items:Array — An array of items to add.
|
uint — The index where the items have been added.
|
| clear | () | method |
public override function clear():voidRemoves all items from the collection.
| dispatchEvent | () | method |
public function dispatchEvent(event:Event):BooleanParameters
event:Event |
Boolean |
| hasEventListener | () | method |
public function hasEventListener(type:String):BooleanParameters
type:String |
Boolean |
| itemRemoved | () | method |
protected override function itemRemoved(item:*, index:uint):voidTemplate method to notify subclasses after an item has been removed.
Parametersitem:* — 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.
Parametersindex:uint — The position of the item to remove.
|
* — The removed item or undefined, if there is no item at that position.
|
| removeItemsAt | () | method |
public override function removeItemsAt(index:uint, numItems:uint):ArrayRemoves a number of items starting at the specified position.
Parametersindex:uint — The position of the first item to remove.
|
|
numItems:uint — The number of items to remove.
|
Array — An array of all removed items.
|
| replaceItemAt | () | method |
public override function replaceItemAt(index:uint, item:*):BooleanReplaces 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.
Parametersindex:uint — The position of the item to replace.
|
|
item:* — The replacing item.
|
Boolean — true, if the item at that position has been replaced..
|
| setArray | () | method |
public override function setArray(array:Array):voidSpecifies an array to be maintained by the list.
Already contained elements will be removed.
Parametersarray:Array — The array.
|
| toString | () | method |
public override function toString():StringInfo
ReturnsString |
| willTrigger | () | method |
public function willTrigger(type:String):BooleanParameters
type:String |
Boolean |
| collectionChanged | event |
as3.collections.fx.events.ArrayListEvent
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:
| Property | Value |
|---|---|
| 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. |
| key | The key of the affected item. Only set for map events. Not set for DATA_SOURCE_REPLACED and COLLECTION_EMPTIED. |