      */
     private function breadthOrderCompare(a:DisplayObject, b:DisplayObject):Number
     {
-        var aParent:DisplayObject = a.parent;
-        var bParent:DisplayObject = b.parent;
-
+        var aParent:DisplayObjectContainer = a.parent;
+        var bParent:DisplayObjectContainer = b.parent;
+        
         if (!aParent || !bParent)
             return 0;
    

import mx.core.FlexGlobals;
import mx.core.IFlexDisplayObject;
import mx.core.IMXMLObject;
import mx.core.IRawChildrenContainer;
import mx.core.UIComponent;
import mx.core.mx_internal;
import mx.events.FlexEvent;

        var aNestLevel:int = (a is UIComponent) ? UIComponent(a).nestLevel : -1;
        var bNestLevel:int = (b is UIComponent) ? UIComponent(b).nestLevel : -1;

        var aIndex:int = 0;
        var bIndex:int = 0;
        
        if (aParent == bParent)
        {
            if (aParent is IVisualElementContainer && a is IVisualElement)
                aIndex = IVisualElementContainer(aParent).getElementIndex(IVisualElement(a));
            else
                aIndex = DisplayObjectContainer(aParent).getChildIndex(a);
                
            if (bParent is IVisualElementContainer && b is IVisualElement)
                bIndex = IVisualElementContainer(bParent).getElementIndex(IVisualElement(b));
            else
                bIndex = DisplayObjectContainer(bParent).getChildIndex(b);
        }
        
        if (aNestLevel > bNestLevel || aIndex > bIndex)
            return 1;
        else if (aNestLevel < bNestLevel ||  bIndex > aIndex)
            return -1;
        else if (a == b)
            return 0;
