Log In  
  Getting Started  
----------------------------------------

Resources

 

The Box class

  • The Box class is the base class for the VBox and HBox classes.
  • VBox container renders all child display objects vertically.
  • HBox container renders all child display objects horizontally.
  • Application object behaves like a VBox by default (vertical layout), but can also be set to use absolute or horizontal layout.
  • VBox and HBox flows like HTML, only in one direction
previous page next page

User rating?

VBox example

The following example code demonstrates the default layout method used by the VBox container (vertical).

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    backgroundColor="#FFFFFF"
    backgroundAlpha="0">

    <mx:VBox>

        <mx:Button label="&lt; prev"
            left="10" top="120" />

        <mx:Image source="assets/animals03.jpg"
            horizontalCenter="0" top="30"/>

        <mx:Label text="Photographed by Elsie Weil"
            horizontalCenter="0" top="250"/>

        <mx:Button label="next &gt;"
            right="10" top="120"/>

    </mx:VBox>

</mx:Application>

Rendered Sample

HBox Example

The following example code demonstrates the default layout method used by the HBox container (horizontal).

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    backgroundColor="#FFFFFF"
    backgroundAlpha="0">

    <mx:HBox>

        <mx:Button label="&lt; prev"
            left="10" top="120" />

        <mx:Image source="assets/animals03.jpg"
            horizontalCenter="0" top="30"/>

        <mx:Label text="Photographed by Elsie Weil"
            horizontalCenter="0" top="250"/>

        <mx:Button label="next &gt;"
            right="10" top="120"/>

    </mx:HBox>

</mx:Application>

Rendered Sample

Box Model: Using both VBox and HBox to achieve the desired layout

The following code nests an HBox inside a VBox demonstrating that container controls can have other containers as children.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
	backgroundColor="#FFFFFF"
	backgroundAlpha="0">

	<mx:VBox horizontalAlign="center"
		verticalGap="15">

		<mx:HBox verticalAlign="middle"
			horizontalGap="15">

			<mx:Button label="&lt; prev"
				left="10" top="120" />

			<mx:Image source="assets/animals03.jpg"
				horizontalCenter="0" top="30"/>

			<mx:Button label="next &gt;"
				right="10" top="120"/>

		</mx:HBox>

		<mx:Label text="Photographed by Elsie Weil"
			horizontalCenter="0" top="250"/>

	</mx:VBox>

</mx:Application>

Rendered Sample

previous page next page
Added by Mark Nichoson , last edited by matthew horn on Apr 22, 2008  (view change)
Labels: 
(None)

Powered by Atlassian Confluence 2.7.1, the Enterprise Wiki. Bug/feature request - Atlassian news - Contact administrators