This content has been marked as final. Show 2 replies
Strictly speaking ArrayCollection doesn't implement and Iterator. That is there is no interface in the hierarchy that it implements or any class that it extends that provides common iterator methods.
This class does inherit createCursor() method from ICollectionView interface which returns an instance of IViewCursor which, as far as I know, is the closest it comes to iterators.
Then of course ActionScript has a built-in collection 'iterator' in the form of 'for each' loop!
I hope it makes some sense that some experienced folks can elaborate this topic further.
ok. I am starting to understand!.
The iterator pattern (in the books) suggests implementing an iterator interface with these 5 methods.
// Returns the current value
// Returns the current key
// Moves the internal pointer to the next element
// Moves the internal pointer to the previous element
// If the current element is valid (boolean)
IViewCursor whose methods ArrayCollection inherits has (amongst many others) these methods
current : Object
[read-only] Provides access the object at the location in the source collection referenced by this cursor.
Moves the cursor to the next item within the collection.
Moves the cursor to the previous item within the collection.
using these you can, in the main, achieve the same things, although it's not right to say it 'uses the iterator pattern' - I suppose as usual the advice it 'use your own judgement - don't rely on the pattern handbook'