Итератор как в php5
Интерфейс:

Код:
interface Iterator // this is interface actually, identical to PHP5 iterator
{
// Returns the current value
public function current();
// Returns the current key
public function key();
// Moves the internal pointer to the next element
public function next():Void
// Moves the internal pointer to the first element
public function rewind():Void;
// If the current element is valid (boolean)
public function valid():Boolean;
}
Итератор для массива

Код:
class ArrayIterator implements Iterator
{
private var p:Number;
private var a:Array;
public function ArrayIterator(arr)
{
this.a = arr;
this.p = 0;
}
// Returns the current value
public function current()
{
return a[p];
}
// Returns the current key
public function key()
{
return p;
}
// Moves the internal pointer to the next element
public function next():Void
{
this.p++;
}
// Moves the internal pointer to the previuos element
public function prev():Void
{
this.p--;
}
// Moves the internal pointer to the first element
public function rewind():Void
{
this.p = 0;
}
// Moves the internal pointer to the last element
public function ff():Void
{
this.p = (this.a.length - 1) ;
}
// If the current element is valid (boolean)
public function valid():Boolean
{
return Boolean(this.p < this.a.length);
}
}