If youâre developing your own components in Flex, sooner or later youâll end up having to deal with the concept of container chrome. This is especially true for developers implementing layout logic in their own custom containers, but even if youâre just writing a simple MXML component, it helps to understand how Flex distinguishes between âchildrenâ and âchrome.â
Hereâs a Panel titled âSearchâ containing one TextInput and one Button labelled âGo.â
All child movie clips of the Panel except the TextInput and the Button are considered to be the Panelâs chrome.
What other child movie clips does the Panel have? Well, the title bar for one (it says âSearchâ). Then thereâs the white background. If the contents donât fit in the available space, the Panel sprouts scrollbars to enable the user to scroll. All these extra movie clips are created and managed by the Panel and its superclasses internally, and theyâre known as the containerâs chrome.
How is chrome different?
The main characteristic of a piece of chrome is that it is created and managed entirely by the containerâs implementation. The UI developer never explicitly adds or directly manipulates the chrome. In the above example, you can feel free to add or remove the TextInput and the Button, either at design time via MXML or dynamically using ActionScript code, but the title bar is something the Panel offers very little control over.
Another difference is when you have scrollbars: only the children scroll, not the chrome.
OK, why do I need to know this?
A lot of new developers may expect to be able to iterate over âallâ the children of a container using the getChildAt and numChildren APIs in the View class.
for (var i = 0; i < panel.numChildren; i++)
trace(panel.getChildAt(i) + "");
Too bad. You donât get a reference to the Panelâs title bar, even though itâs a âchildâ of the Panel⦠because really itâs not a child, itâs chrome.
How do I access the chrome then?
The only way to access a containerâs chrome is by using API exposed by the container. For example, in the DividedBox, the dividers can be accessed using the getDividerAt method. The Panel, on the other hand, does not expose its title bar, so thereâs no way to access and manipulate it directly (low-level hacks aside).
So again, how can I iterate over all the children of a container?