Specifications

CHAPTER 4
80
When you nest containers, each container instance runs measuring and sizing algorithms on its children (some
of which are containers themselves, so this measuring procedure can be recursive). When the layout algorithms
have processed, and the relative layout values have been calculated, Flash Player draws the complex collection of
objects comprising the view. By eliminating unnecessary work at object creation time, you can improve the perfor-
mance of your application.
Using Grid containers
A Grid container is useful for aligning multiple objects. When you use Grid containers, however, you introduce
additional levels of containers with the GridItem and GridRow controls. In many cases, you can achieve the same
results by using the VBox and HBox containers, and these containers use fewer levels of nesting.
Using layout containers
You can sometimes improve application start-up time by using Canvas containers, which perform absolute
positioning, instead of relative layout containers, such as the Form, HBox, VBox, Grid, and Tile containers.
Canvas containers are the only containers that let you specify the location of their child controls by default. All
other containers are relative containers by default, which means that they lay everything out relative to other
components in the container. You can make Application and Panel containers do absolute positioning.
Canvas containers eliminate the layout logic that other containers use to perform automatic positioning of their
children at startup, and replace it with explicit pixel-based positioning. When you use a Canvas container, you
must remember to set the x and y positions of all of its children. If you do not set the x and y positions, the Canvas
container’s children lay out on top of each other at the default x, y coordinates (0,0).
The canvas container is not always more efficient than other containers, however, because it must measure itself
to make sure that it is large enough to contain its children. Applications that use canvases typically contain a much
flatter containment hierarchy. As a result, using canvas containers can lead to less nesting and fewer overall
containers, which improves performance.
Canvas containers support constraints, which means that if the container changes size, the children inside the
container move with it.
Using absolute sizing
Writing object widths and heights into the code can save time because the Flex layout containers do not have to
calculate the size of the object at run time. By specifying container or control widths or heights, you lighten the
relative layout container’s processing load and subsequently decrease the creation time for the container or
control. This technique works with any container or control.