Packagemx.collections
Classpublic class AsyncListView
InheritanceAsyncListView Inheritance OnDemandEventDispatcher Inheritance Object
Implements IList

Language Version: ActionScript 3.0
Product Version: Flex 3
Runtime Versions: Flash Player 9, AIR 1.1

A "wrapper" for IList implementations that handles ItemPendingErrors thrown by getItemAt().

The getItemAt() method handles ItemPendingErrors by returning a provisional "pending" item until the underlying request succeeds or fails. The provisional item is produced by calling createPendingItemFunction. If the request succeeds, the actual item replaces the provisional one, and if it fails the provisional item is replaced by with the item returned by calling createFailedItemFunction.

This class delegates the IList methods and properties to its list. If a list isn't specified, methods that mutate the collection are no-ops, and methods that query the collection return an "empty" value like null or zero as appropriate.

This class is intended to be used with Spark components based on DataGroup, like List and ComboBox, which don't provide intrinsic support for ItemPendingError handling.



Public Properties
 PropertyDefined By
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
  createFailedItemFunction : Function
A function that's used to create a substitute item when a request which had caused an ItemPendingError to be thrown, subsequently fails.
AsyncListView
  createPendingItemFunction : Function
A function that's used to create a provisional item when the initial request causes an ItemPendingError to be thrown.
AsyncListView
  length : int
[read-only] The number of items in this collection.
AsyncListView
  list : IList
The IList that this collection view "wraps", i.e.
AsyncListView
 Inheritedprototype : Object
[static] A reference to the prototype object of a class or function object.
Object
Public Methods
 MethodDefined By
  
AsyncListView(list:IList = null)
AsyncListView constructor.
AsyncListView
 Inherited
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
OnDemandEventDispatcher
  
Adds the specified item to the end of the list.
AsyncListView
  
addItemAt(item:Object, index:int):void
Adds the item at the specified index.
AsyncListView
 Inherited
OnDemandEventDispatcher
  
getItemAt(index:int, prefetch:int = 0):Object
Returns the value of list.getItemAt(index).
AsyncListView
  
Returns the index of the item if it is in the list such that getItemAt(index) == item.
AsyncListView
 Inherited
OnDemandEventDispatcher
 Inherited
Indicates whether an object has a specified property defined.
Object
 Inherited
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
Notifies the view that an item has been updated.
AsyncListView
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
  
Removes all items from the list.
AsyncListView
 Inherited
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
OnDemandEventDispatcher
  
Removes the item at the specified index and returns it.
AsyncListView
  
setItemAt(item:Object, index:int):Object
Places the item at the specified index.
AsyncListView
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
  
Returns an Array that is populated in the same order as the IList implementation.
AsyncListView
 Inherited
Returns the string representation of this object, formatted according to locale-specific conventions.
Object
  
Prints the contents of this view to a string and returns it.
AsyncListView
 Inherited
Returns the primitive value of the specified object.
Object
 Inherited
OnDemandEventDispatcher
Events
 Event Summary Defined By
  Dispatched when the list's length has changed or when a list element is replaced.AsyncListView
Property Detail
createFailedItemFunctionproperty
createFailedItemFunction:Function

A function that's used to create a substitute item when a request which had caused an ItemPendingError to be thrown, subsequently fails. The existing item, typically a pending item created with the value of createPendingItemFunction(), is replaced with the failed item.

The value of this property must be a function with two parameters, the index of the requested item, and the failure "info" object, which is passed along from the IResponder fault() method. In most cases second parameter can be ignored, e.g.:

     function createFailedItem(index:int, info:Object):Object
     {
         return "[" + index + "request failed]";        
     }
       

Setting this property does not affect failed items that were already created. Setting this property to null will prevent failed items from being created.

The default value is A function that unconditionally returns null..



Implementation
    public function get createFailedItemFunction():Function
    public function set createFailedItemFunction(value:Function):void

See also

getItemAt
createPendingItemFunction
mx.rpc.IResponder.fault
createPendingItemFunctionproperty 
createPendingItemFunction:Function

A function that's used to create a provisional item when the initial request causes an ItemPendingError to be thrown. If the request eventually succeeds, the provisional item is automatically replaced by the actual item. If the request fails, then the item is replaced with one created with the createFailedItemFunction.

The value of this property must be a function with two parameters, the index of the requested dataProvider item, and the ItemPendingError itself. In most cases second parameter can be ignored, e.g.:

     function createPendingItem(index:int, ipe:ItemPendingError):Object
     {
         return "[" + index + "request is pending...]";        
     }
       

Setting this property does not affect provisional pending items that were already created. Setting this property to null will prevent provisional pending items from being created.

The default value is A function that unconditionally returns null..



Implementation
    public function get createPendingItemFunction():Function
    public function set createPendingItemFunction(value:Function):void

See also

lengthproperty 
length:int  [read-only]

Language Version: ActionScript 3.0
Product Version: Flex 3
Runtime Versions: Flash Player 9, AIR 1.1

The number of items in this collection. 0 means no items while -1 means the length is unknown.

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



Implementation
    public function get length():int
listproperty 
list:IList

Language Version: ActionScript 3.0
Product Version: Flex 3
Runtime Versions: Flash Player 9, AIR 1.1

The IList that this collection view "wraps", i.e. the object to which all of the IList metods are delegated.

If this property is null, the IList mutation methods, like setItemAt(), are no-ops and the IList query methods, like getItemAt() return, null or zero (-1 for getItemIndex()), as appropriate.

The default value is null.

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



Implementation
    public function get list():IList
    public function set list(value:IList):void
Constructor Detail
AsyncListView()Constructor
public function AsyncListView(list:IList = null)

Language Version: ActionScript 3.0
Product Version: Flex 3
Runtime Versions: Flash Player 9, AIR 1.1

AsyncListView constructor.

Parameters
list:IList (default = null) — Initial value of the list property, the IList we're delegating to.
Method Detail
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

Adds 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

Adds the item at the specified index. The index of any item greater than the index of the added item is increased by one. If the the specified index is less than zero or greater than the length of the list, a RangeError is thrown.

Parameters

item:Object — The item to place at the index.
 
index:int — The index at which to place the item.

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

Returns the value of list.getItemAt(index).

This method catches ItemPendingErrors (IPEs) generated as a consequence of calling getItemAt(). If an IPE is thrown, an IResponder is added to the IPE and a provisional "pending" item, created with the createPendingItemFunction is returned. If the underlying request eventually succeeds, the pending item is replaced with the real item. If it fails, the pending item is replaced with a value produced by calling createFailedItemFunction.

Parameters

index:int — The list index from which to retrieve the item.
 
prefetch:int (default = 0) — An int indicating both the direction and number of items to fetch during the request if the item is not local.

Returns
Object — The list item at the specified index.

Throws
RangeError — if index < 0 or index >= length.

See also

createPendingItemFunction
createFailedItemFunction
mx.collections.errors.ItemPendingError
mx.rpc.IResponder
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

Returns the index of the item if it is in the list such that getItemAt(index) == item.

Note: unlike IViewCursor.findxxx() methods, The getItemIndex() method cannot take a parameter with only a subset of the fields in the item being serched for; this method always searches for an item that exactly matches the input parameter.

Parameters

item:Object — The item to find.

Returns
int — The index of the item, or -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

Notifies the view that an item has been updated. This is useful if the contents of the view do not implement IEventDispatcher and dispatches a PropertyChangeEvent. 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) — The name of 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.)

removeAll()method 
public function removeAll():void

Language Version: ActionScript 3.0
Product Version: Flex 3
Runtime Versions: Flash Player 9, AIR 1.1

Removes all items from the list.

If any item is not local and an asynchronous operation must be performed, an ItemPendingError will be thrown.

See the ItemPendingError documentation as well as the collections documentation for more information on using the ItemPendingError.

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

Removes the item at the specified index and returns 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.
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

Places 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 item to be placed at the specified index.
 
index:int — The index at which to place the item.

Returns
Object — The item that was replaced, or null if none.
toArray()method 
public function toArray():Array

Language Version: ActionScript 3.0
Product Version: Flex 3
Runtime Versions: Flash Player 9, AIR 1.1

Returns an Array that is populated in the same order as the IList implementation. This method can throw an ItemPendingError.

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

Language Version: ActionScript 3.0
Product Version: Flex 3
Runtime Versions: Flash Player 9, AIR 1.1

Prints the contents of this view to a string and returns it.

Returns
String — The contents of this view, in string form.
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 list's length has changed or when a list element is replaced.

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.

PropertyValue
bubblesfalse
cancelablefalse
currentTargetThe 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.
itemsAn 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
kindThe kind of event. The valid values are defined in the CollectionEventKind class as constants.
locationLocation within the target collection of the item(s) specified in the items property.
oldLocationthe previous location in the collection of the item specified in the items property.
targetThe 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.
typeCollectionEvent.COLLECTION_CHANGE