The following list provides examples of common container redundancies to avoid:
The VBox container inside an <mx:Panel> tag—A Panel container is a VBox container with support for a title bar, rounded borders, and other Panel styles. If you want Panel children to lay out as they would in a VBox container, populate the <mx:Panel> tag directly with controls; do not wrap a VBox container around the controls. The VBox container would be a redundant container wrapper, and removing this eliminates one more level of unnecessary container nesting.
For example, instead of writing this:
<mx:Panel title="Grocery List" width="150" height="150"> <mx:VBox> <mx:Label text="Fruits" /> <mx:Label text="Veggies" /> <mx:Label text="Cookies" /> <mx:Label text="Crackers" /> </mx:VBox> </mx:Panel>
Use this code instead:
<mx:Panel title="Grocery List" width="150" height="150"> <mx:Label text="Fruits" /> <mx:Label text="Veggies" /> <mx:Label text="Cookies" /> <mx:Label text="Crackers" /> </mx:Panel>
Both achieve an identical layout.
VBox container inside an <mx:Application> tag—An Application object is inherently a VBox container layout. It is unnecessary to wrap your <mx:Application> tag with a VBox container; removing this wrapper will eliminate one more level of container nesting.
For example, instead of writing this:
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml">
<mx:VBox horizontalAlign="center" backgroundColor="#EFEFEF">
<mx:Label label="Shopping Cart" />
.
.
.
</mx:VBox>
</mx:Application>
Use this code instead:
<mx:Application xmlns:mx=http://www.macromedia.com/2003/mxml
horizontalAlign="center" backgroundColor="#EFEFEF">
<mx:Label label="Shopping Cart" />
.
.
.
</mx:Application>
Containers as top-level tags for MXML components—The beauty of MXML components is that they provide a way to modularize repeated code. However, these components are vulnerable to the same performance pitfalls as the larger application. You do not need to use a container tag as the top-level tag of your MXML component definition. It is perfectly valid for an MXML component to be a simple control, like:
<mx:Image xmlns:mx=http://www.macromedia.com/2003/mxml source="@embed('foo.jpg')" width="200" height="200" />
By stepping through MXML component definitions and purging unneeded container wrappers, you can reduce container nesting (and many unnecessary objects), and, subsequently, ease the load of your application.
Container wrappers for an MXML component instance—
Normally, there is no need to wrap a container around an MXML component
tag. You can set different styles, labels, and ids within the instance
of the MXML component—you don't need to set them within a container
that wraps the MXML component. For example, instead of wrapping
an unnecessary VBox container around your MXML component to set
some styles like this:
<mx:VBox backgroundColor=" #FFCCCC" borderStyle=" solid"> <myComponent xmlns=" *" /> </mx:VBox>
You can set those styles within the MXML component tag itself, like this:
<myComponent xmlns=" *" backgroundColor=" #FFCCCC" borderStyle=" solid" />
Developers often couple this bad practice with using unnecessary containers as top-level tags for MXML components, which can create at least two superfluous containers for each MXML component used! This creates many unused objects that, when eliminated, yield a dramatic improvement in the responsiveness of your application.