<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
                layout="absolute" 
                creationComplete="this.init();" >
                
    <mx:Script>
        <![CDATA[
            //import IIterator, IteratorFactory, IteratorTypes
            import com.ericfeminella.utils.iterators.IIterator;
            import com.ericfeminella.utils.iterators.IteratorFactory;
            import com.ericfeminella.utils.iterators.IteratorTypes;
            import mx.collections.ArrayCollection;
            
            private function init():void
            {
                // define a new iterator instance and type the iterator as an IIterator Interface
                var it:IIterator;
                
                // invoke IteratorFactory.getIterator(); to return the type of iterator needed, in 
                //this case an ArrayIterator
                it = IteratorFactory.getIterator(IteratorTypes.ARRAY_ITERATOR);
                // set the aggregate to iterate over, in this case an Array
                it.setAggregate(['Iterator Example','Version 1.0']); 
                
                // call hasNext() to loop over the array
                while (it.hasNext())
                {
                    // trace out the contents of the array by calling next();
                    trace(it.next());
                    // Iterator Example
                    // Version 1.0
                }
                
                // invoke IteratorFactory.getIterator(); to return the type of iterator
                // needed, in this case an ArrayCollectionIterator
                it = IteratorFactory.getIterator(IteratorTypes.ARRAY_COLLECTION_ITERATOR);
                // set the aggregate to iterate over, in this case an ArrayCollection
                it.setAggregate(new ArrayCollection([{name:"Iterator Example"}]));
                
                // call hasNext() to loop over the ArrayCollection
                while (it.hasNext())
                {
                    // trace out the items of the collection by calling next();
                    trace(it.next().name);
                    // Iterator Example
                }
                
                // invoke IteratorFactory.getIterator(); to return the type of iterator needed, in this case an ObjectIterator
                it = IteratorFactory.getIterator(IteratorTypes.OBJECT_ITERATOR);
                // set the aggregate to iterate over, in this case an Object
                it.setAggregate({name:"Iterator Example", version: 1.0});
                
                while (it.hasNext())
                {
                    // trace out the property values of the object by calling next();
                    trace(it.next());
                    // Iterator Example
                    // 1.0
                } 
            }
        ]]>
    </mx:Script>
    
</mx:Application>