TraverseArrayEnumerator
| Kind of class: | class |
|---|---|
| Inherits from: | ArrayEnumerator < Enumerator < Dispatcher |
| Author: | Arthur Clemens |
| Classpath: | org.asapframework.data.array.TraverseArrayEnumerator |
| File last modified: | Thursday, 12 October 2006, 11:19:40 |
Enhanced array enumerator, with the option to loop. TraverseArrayEnumerator sends out traverse events of type TraverseArrayEnumeratorEvent.UPDATE.
A TraverseArrayEnumerator can be used with a paging controller to navigate through a list of thumbs or search result pages (see example below).
A TraverseArrayEnumerator can be used with a paging controller to navigate through a list of thumbs or search result pages (see example below).
Usage:
- Example for a enumerator that handles a row of thumbs.
private function PagingController (inTimeline:MovieClip) { // Create thumb image list: var thumbList:Array = createThumbs(); // Create traverse enumerator for this list mThumbPager = new TraverseArrayEnumerator(thumbList); // Subscribe to update events so the previous and next buttons can be updated: mThumbPager.addEventListener(TraverseArrayEnumeratorEvent.UPDATE, EventDelegate.create(this, handleThumbUpdate)); // Highlight first thumb and load corresponding image: activateThumb(mThumbPager.getNextObject()); }
In this example the previous, next and thumb image buttons are subclasses of org.asapframework.ui.buttons.EventButton:public function onEventButtonPress ( e:EventButtonEvent ) : Void { if (e.target instanceof ThumbImage) { var thumb:ThumbImage = ThumbImage(e.target); var oldThumb:ThumbImage = mThumbPager.getCurrentObject(); mThumbPager.setCurrentObject(thumb); // will update the enumerator activateThumb(thumb, oldThumb); } if (e.target instanceof NextButton) { var oldThumb:ThumbImage = mThumbPager.getCurrentObject(); var newThumb:ThumbImage; if (e.target._name == "next_btn") { newThumb = mThumbPager.getNextObject(); } if (e.target._name == "previous_btn") { newThumb = mThumbPager.getPreviousObject(); } activateThumb(newThumb, oldThumb); } }
Update the previous and next button with each change:private function handleThumbUpdate (e:TraverseArrayEnumeratorEvent) : Void { next_btn.setEnabled(mThumbPager.hasNextObject()); previous_btn.setEnabled(mThumbPager.hasPreviousObject()); }
Thumb update function:private function activateThumb (inThumb:ThumbImage, inOldThumb:ThumbImage) : Void { if (inOldThumb) { inOldThumb.setSelected(false); } inThumb.setSelected(true); loadImage(inThumb.getId()); }
Events broadcasted to listeners:
- TraverseArrayEnumeratorEvent with type:
UPDATEIf the delegate validation method exists and only if the delegate method returns true.- (null)
Summary
Constructor
- TraverseArrayEnumerator (inArray:Array, inDoLoop:Boolean)
- Creates a new array enumerator.
Instance properties
- mTraverseOptions : Number
- mDelegateObject : Object
- mDelegateMethod : Object
- traverseOptions (inTraverseOptions:Number) : Number
- The traversal options; see TraverseArrayOptions.
Instance properties inherited from ArrayEnumerator
Instance properties inherited from Dispatcher
Instance methods
- setLoop (inDoLoop:Boolean) : Void
- Set the looping property of the enumerator.
- setDelegate (inDelegateObject:Object, inDelegateMethod:Object) : Void
- A delegate validation method is called in update when a delegate object is set.
- getNextObject (inTraverseOptions:Number)
- Increments the location pointer by one and returns the object from the array at that location.
- getPreviousObject (inTraverseOptions:Number)
- Decrements the location pointer by one and returns the object from the array at that location.
- hasNextObject (inTraverseOptions:Number) : Boolean
- Checks if there is an object after the current object.
- hasPreviousObject (inTraverseOptions:Number) : Boolean
- Checks if there is an object before the current object.
- performGetNextObject (inTraverseOptions:Number) : Number
- performGetPreviousObject (inTraverseOptions:Number) : Number
- update (inLocation:Number)
- If a delegate object has been set, its validation method is called before setting the new node.
Instance methods inherited from ArrayEnumerator
Instance methods inherited from Enumerator
Constructor
TraverseArrayEnumerator
function TraverseArrayEnumerator (
inArray:Array,
inDoLoop:Boolean)
Creates a new array enumerator. Optionally stores a pointer to array inArray.
Parameters:
inArray :
(optional) the array to enumerate
inDoLoop:
if true, the enumerator will loop past the end of the array to the start (and back when traversing backwards)
Instance properties
mDelegateMethod
private mDelegateMethod:Object
(read)
mDelegateObject
private mDelegateObject:Object
(read)
mTraverseOptions
private mTraverseOptions:Number = TraverseArrayOptions.NONE
(read)
Instance methods
getNextObject
function getNextObject (
inTraverseOptions:Number)
Increments the location pointer by one and returns the object from the array at that location.
Returns:
- (Deliberately untyped) The object at the new location. Returns null if the location pointer has moved past the end of the array and inTraverseOptions is not set to TraverseArrayOptions.LOOP.
Implementation note:
- Calls update.
getPreviousObject
function getPreviousObject (
inTraverseOptions:Number)
Decrements the location pointer by one and returns the object from the array at that location.
Returns:
- (Deliberately untyped) The object at the new location. Returns null if the location pointer has moved past the end of the array and inTraverseOptions is not set to TraverseArrayOptions.LOOP.
Implementation note:
- Calls update.
hasNextObject
function hasNextObject (
inTraverseOptions:Number) : Boolean
Checks if there is an object after the current object.
Returns:
- True: there is a next object; false: the current object is the last.
hasPreviousObject
function hasPreviousObject (
inTraverseOptions:Number) : Boolean
Checks if there is an object before the current object.
Returns:
- True: there is a next object; false: the current object is the first.
performGetNextObject
private function performGetNextObject (
inTraverseOptions:Number) : Number
Returns:
- The next location; -1 if the next location is not valid.
performGetPreviousObject
private function performGetPreviousObject (
inTraverseOptions:Number) : Number
Returns:
- The previous location; -1 if the previous location is not valid.
setDelegate
function setDelegate (
inDelegateObject:Object,
inDelegateMethod:Object) : Void
A delegate validation method is called in update when a delegate object is set. The delegate's validation method is called to evaluate the new node before it is set.
Parameters:
inDelegateObject:
the owner of the delegate method
inDelegateMethod:
Node validation method (method name or function reference). This method should accept an Object as parameter and return a Boolean to indicate the item's validity.
setLoop
function setLoop (
inDoLoop:Boolean) : Void
Set the looping property of the enumerator.
Parameters:
inDoLoop:
if true, the enumerator will loop past the end of the array to the start (and back when traversing backwards)
Implementation note:
update
private function update (
inLocation:Number)
If a delegate object has been set, its validation method is called before setting the new node. If the validation method returns false, this method will return null
Returns:
- (Deliberately untyped) The object from the array at the new position.
Events broadcasted to listeners:
- TraverseArrayEnumeratorEvent with type:
UPDATEIf the delegate validation method exists and only if the delegate method returns true.- (null)
Overrides: