A Simple ActionScript 3 Iterator Implementation

| 1 Comment | No TrackBacks

I was looking for an Iterator implementation in ActionScript 3 to avoid reinventing the wheel for the umpteenth time but couldn't find one on Google, so I whipped one up quick that you can download here. This should save someone a full 3 minutes of work in the future....

Usage is pretty simple and straightforward. The download includes the Iterator interface as well as a simple implementation of ArrayIterator for iterating over an array of elements:

import com.darronschall.util.*;

var arr:Array = [1, 2, 3];
var it:Iterator = new ArrayIterator( arr );
while ( it.hasNext() )
{
	trace( it.next() );  // 1, 2, 3
}
		
var it2:Iterator = new ArrayIterator( null );
trace( it2.hasNext() ); // false

You can use this code without restriction under the MIT License.

Tags: , , ,

No TrackBacks

TrackBack URL: http://www.darronschall.com/mt/mt-tb.cgi/113

1 Comment

Hello Darron,
thanks for sharing,
I'm using existing api but have been looking for different imlementation to have less dependancy on flex sdk:
sample based on existing sdk:

var arr:Array = [1, 2, 3]
var ic:IViewCursor = new ArrayCollection(arr).createCursor();
while(!ic.afterLast){
trace(ic.current);
ic.moveNext()
};
arr = [];
ic = new ArrayCollection(arr).createCursor();
trace(ic.moveNext());

regards,
Peter Blazejewicz

Leave a comment



About this Entry

This page contains a single entry by darron published on June 6, 2006 8:47 AM.

It just works was the previous entry in this blog.

The Future of ActionScript is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Archives

OpenID accepted here Learn more about OpenID
Powered by Movable Type 5.02