         targetStack.addEventListener(IndexChangedEvent.CHILD_INDEX_CHANGE,
                                      childIndexChangeHandler);
 
-        var numViews:int = targetStack.numChildren;
-
-        for (var i:int = 0; i < numViews; i++)
-        {
-            var child:Container = Container(targetStack.getChildAt(i));
+        numViews = targetStack.numChildren;
+
+        for (i = 0; i < numViews; i++)
+        {
+            child = Container(targetStack.getChildAt(i));
             var item:Button = Button(createNavItem(itemToLabel(child), child.icon));
 
                  

        // such as when a TabBar is inside a TabNavigator.
        if (event.target == this)
            return;

        var viewStack:ViewStack = ViewStack(event.target);
        removeChildAt(viewStack.getChildIndex(event.relatedObject));


            targetStack.removeEventListener(
                IndexChangedEvent.CHILD_INDEX_CHANGE, childIndexChangeHandler);

            var numViews:int = targetStack.numChildren;
            var child:Container;

            for (var i:int = 0; i < numViews; i++)
	        {
                child = Container(targetStack.getChildAt(i));

                child.removeEventListener("labelChanged", labelChangedHandler);
                child.removeEventListener("iconChanged", iconChangedHandler);
                child.removeEventListener("enabledChanged", enabledChangedHandler);
                child.removeEventListener("toolTipChanged", toolTipChangedHandler);
            }
        }

        // Clear out the current links
