Docked ApplicationControlBar Is Not In Children List

Here is a funny thing about how ApplicationControlBar acts differently as a child when docked and not docked.

I had to write some code that traverse the complete tree of components in a flex application, and that was when I first discovered about rawChildren lists. It turns out, that not all components are added as children to containers. Some are added as rawChildren instead. I first thought this to be for stuff like borders, title bars, dividers, … that does not have real meaning for the application, as for instance input fields and buttons has.

Well, it turns out I was wrong. The mx.core.Application container has special handling for mx.containers.ApplicationControlBar. Here is the source code for Application.dockControlBar:

    mx_internal function dockControlBar(controlBar:IUIComponent,
            dock:Boolean):void
    {
        if (dock)
        {
            try
            {
                removeChild(DisplayObject(controlBar));
            }
            catch(e:Error)
            {
                return;
            }

            rawChildren.addChildAt(DisplayObject(controlBar), firstChildIndex);
            setControlBar(controlBar);
        }
        else // undock
        {
            try
            {
                rawChildren.removeChild(DisplayObject(controlBar));
            }
            catch(e:Error)
            {
                return;
            }

            setControlBar(null);
            addChildAt(DisplayObject(controlBar), 0);
        }
    }

as you can see, if the control bar is in docked state, it will be added only to the rawChildren list and not to the children list. And vice versa.

What this meant to me was, that when I traversed children lists of containers down in the component hierarchy, I did not see the ApplicationControlBar instance.

Well, lesson learned.

December 29, 2008 В· polesen В· Comments Closed
Tags:  В· Posted in: Programming, Rich Internet Applications