 import mx.effects.Effect;
 import mx.effects.EffectManager;
 import mx.events.ChildExistenceChangedEvent;
+import mx.events.CollectionEvent;
+import mx.events.CollectionEventKind;
 import mx.events.EffectEvent;
 import mx.events.FlexEvent;
 import mx.events.IndexChangedEvent;
+import mx.events.PropertyChangeEvent;
 import mx.geom.RoundedRectangle;
 import mx.managers.HistoryManager;
+import mx.managers.IHistoryManagerClient;
 
 use namespace mx_internal;
 


        if (lastIndex != -1 && lastIndex < numChildren)
        {
            var currentChild:Container = Container(getChildAt(lastIndex));

            currentChild.setVisible(false); // Hide the current child


            invalidateProperties();
        }
    }
  

    /**
     *  @private
     */
    override public function addChildAt(item:DisplayObject, index:int):DisplayObject
    {
        var obj:DisplayObject = super.addChildAt(item, index);
        internalDispatchEvent(CollectionEventKind.ADD, obj, index);
        return obj;
    }

    /**
     *  @private
     */
    override public function removeChildAt(index:int):DisplayObject
    {
        var obj:DisplayObject = super.removeChildAt(index);
        internalDispatchEvent(CollectionEventKind.REMOVE, getItemAt(index), index);
        return obj;
    }

    /**
     *  @private
     */
    override public function removeAllChildren():void
    {
        super.removeAllChildren();
        internalDispatchEvent(CollectionEventKind.RESET);
    }

    //--------------------------------------------------------------------------
    //
    //  IList Implementation
    //  Viewstack implements IList so it can be plugged into a Spark ButtonBar
    //
    //--------------------------------------------------------------------------

    /**
     *  @private
     *  The IList implementation dispatches change events when 
     *  label or icon properties change.
     */
    private function navigatorChildChangedHandler(event:Event):void
    {
        var pe:PropertyChangeEvent = new PropertyChangeEvent(PropertyChangeEvent.PROPERTY_CHANGE);
        pe.source = event.target;
        pe.property = (event.type == "labelChanged") ? "label" : "icon";

        internalDispatchEvent(CollectionEventKind.UPDATE, pe, getChildIndex(event.target as DisplayObject));
    }

    /**
     *  Dispatches a collection event with the specified information.
     *
     *  @param kind String indicates what the kind property of the event should be
     *  @param item Object reference to the item that was added or removed
     *  @param location int indicating where in the source the item was added.
     *  
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    private function internalDispatchEvent(kind:String, item:Object = null, location:int = -1):void
    {
        if (hasEventListener(CollectionEvent.COLLECTION_CHANGE))
        {
            var event:CollectionEvent =
                new CollectionEvent(CollectionEvent.COLLECTION_CHANGE);
            event.kind = kind;
            event.items.push(item);
            event.location = location;
            dispatchEvent(event);
        }

        // now dispatch a complementary PropertyChangeEvent
        if (hasEventListener(PropertyChangeEvent.PROPERTY_CHANGE) && 
           (kind == CollectionEventKind.ADD || kind == CollectionEventKind.REMOVE))
        {
            var objEvent:PropertyChangeEvent =
                new PropertyChangeEvent(PropertyChangeEvent.PROPERTY_CHANGE);
            objEvent.property = location;
            if (kind == CollectionEventKind.ADD)
                objEvent.newValue = item;
            else
                objEvent.oldValue = item;
            dispatchEvent(objEvent);
        }
    }

    /**
     *  @private
     *  IList implementation of length returns numChildren
     */
    public function get length():int
    {
    	return numChildren;
    }

    /**
     *  @private
     *  IList implementation of addItem calls addChild
     */
    public function addItem(item:Object):void
    {
    	addChild(item as DisplayObject);
    }

    /**
     *  @private
     *  IList implementation of addItemAt calls addChildAt
     */
    public function addItemAt(item:Object, index:int):void
    {
    	addChildAt(item as DisplayObject, index);
    }

    /**
     *  @private
     *  IList implementation of getItemAt calls getChildAt
     */
    public function getItemAt(index:int, prefetch:int = 0):Object
    {
    	return getChildAt(index);
    }

    /**
     *  @private
     *  IList implementation of getItemIndex calls getChildIndex
     */
    public function getItemIndex(item:Object):int
    {
    	return getChildIndex(item as DisplayObject);
    }

    /**
     *  @private
     *  IList implementation of itemUpdated doesn't do anything
     */
    public function itemUpdated(item:Object, property:Object = null, 
                         oldValue:Object = null, 
                         newValue:Object = null):void
    {
    	
    }                         

    /**
     *  @private
     *  IList implementation of removeAll calls removeAllChildren
     */
    public function removeAll():void
    {
    	removeAllChildren();
    }

    /**
     *  @private
     *  IList implementation of removeItemAt calls removeChildAt
     */
    public function removeItemAt(index:int):Object
    {
        return removeChildAt(index);
    }

    /**
     *  @private
     *  IList implementation of setItemAt removes the old
     *  child and adds the new
     */
    public function setItemAt(item:Object, index:int):Object
    {
    	var result:Object = removeChildAt(index);
    	addChildAt(item as DisplayObject,index);
    	return result;
    }

    /**
     *  @private
     *  IList implementation of toArray returns array of children
     */
    public function toArray():Array 
    {
        var result:Array = [];
        for(var i:int =0;i<numChildren;i++)
        {
        	result.push(getChildAt(i));
        }
        return result;
    }
    
    
}

}
