Chapter 3. Containers

The term containers generally refers to all the classes held in the mx.containers package of the Flex Framework. Containers extend the UIComponent class, adding layout management functionality, methods to control the creation of children using creation policies, and automatic scrolling. The implementations of containers are quite distinct, but all share the ability to position children, lay out those children by using constraints or styles, and control scrolling and how those children respond to scroll events.

Constraints are new to Flex 3. They enable developers to create rules for positioning, in terms of both location and sizing, to which the children of containers can be assigned. Constraints work only with containers, such as the Canvas container, that have absolute positioning, which has much the same meaning as it does in CSS. Box and Tile containers provide automatic layout of children and methods for controlling which children are included in the layout management.

3.1. Position Children by Using Layout Management

Problem

You need to position multiple children vertically or horizontally and control the layout of those children.

Solution

Use the HBox or VBox container, and set the horizontalGap or verticalGap for the HBox or VBox, respectively, to set the distance between the components.

Discussion

Extending the common base class mx.containers.Box, the HBox and VBox components lay out their children horizontally or vertically, respectively, and can hold an ...

Get Flex 3 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.