Controls are user-interface components, such as Button, TextArea, and ComboBox controls. You place controls in containers, which are user-interface components that provide a hierarchical structure for controls and other containers. Typically, you define a container, and then insert controls or other containers in it.
At the root of a Flex application is the <mx:Application> tag, which represents a base container that covers the entire Adobe® Flash® Player or Adobe AIR™ drawing surface. You can place controls or containers directly under the <mx:Application> tag or in other containers. For more information on containers, see Introducing Containers.
Most controls have the following characteristics:
The following image shows several controls used in a Form container:
The MXML and ActionScript APIs let you create and configure a control. The following MXML code example creates a TextInput control in a Form container:
<?xml version="1.0"?>
<!-- controls\TextInputInForm.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Form width="300" height="100">
<mx:FormItem label="Card Name">
<mx:TextInput id="cardName"/>
</mx:FormItem>
</mx:Form>
</mx:Application>
The executing SWF file for the previous example is shown below:
This example produces the following image:
Although you commonly use MXML as the language for building Flex applications, you can also use ActionScript to configure controls. For example, the following code example populates a DataGrid control by providing an Array of items as the value of the DataGrid control's dataProvider property:
<?xml version="1.0"?>
<!-- controls\DataGridConfigAS.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
private function myGrid_initialize():void {
myGrid.dataProvider = [
{Artist:'Steve Goodman', Album:'High and Outside', Price:8.99},
{Artist:'Carole King', Album:'Tapestry', Price:11.99},
{Artist:'The Beach Boys', Album:'Pet Sounds', Price:13.99},
{Artist:'Original Cast', Album:'Camelot', Price:9.99} ];
}
]]>
</mx:Script>
<mx:DataGrid id="myGrid"
width="350" height="150"
color="#7B0974"
creationComplete="myGrid_initialize();"/>
</mx:Application>
The executing SWF file for the previous example is shown below:
This example produces the following image:
Several Flex components display text or take text input, as the following table shows:
|
Control |
Type of text |
|---|---|
|
Label |
Noneditable, single-line text field |
|
Text |
Noneditable, multiline text field |
|
TextInput |
(Optional) Editable, single-line text field |
|
TextArea |
(Optional) Editable, multiline text field |
|
RichTextEditor |
Compound control that contains a multiline text field and controls that let you format text by selecting such characteristics as font, size, weight, and alignment |
These controls can display plain text that all has the same appearance. The controls can also display rich text formatted by using a subset of the standard HTML formatting tags. For information on using text controls, see Using Text Controls.
Several Flex components, such as the DataGrid, Tree, and ComboBox controls, take input data from a data provider. A data provider is a collection of objects, similar to an array. For example, a Tree control reads data from the data provider to define the structure of the tree and any associated data assigned to each tree node.
The data provider creates a level of abstraction between Flex components and the data that you use to populate them. You can populate multiple components from the same data provider, switch data providers for a component at run time, and modify the data provider so that changes are reflected by all components that use the data provider.
Consider that the data provider is the model, and the Flex components are the view onto the model. By separating the model from the view, you can change one without changing the other.
Several Flex controls create or interact with menus, as the following table shows:
|
Control |
Description |
|---|---|
|
Menu |
A visual menu that can have cascading submenus |
|
MenuBar |
A horizontal bar with multiple submenus |
|
PopUpMenuButton |
A Menu control that opens when you click a button |
For information on menu controls, see Using Menu-Based Controls.
The following table lists all the controls available with Flex:
|
Control |
Description |
For more information |
|---|---|---|
|
Alert |
Displays a pop-up alert |
|
|
Button |
Displays a variable-size button that can include a label, an icon image, or both. |
|
|
ButtonBar |
Displays a row of related buttons with a common appearance. |
|
|
CheckBox |
Shows whether a particular Boolean value is true (checked) or false (unchecked). |
|
|
ComboBox |
Displays a drop-down list attached to a text field that contains a set of values. |
|
|
ColorPicker |
Displays a selectable drop-down color swatch panel (palette). |
|
|
DataGrid |
Displays data in a tabular format. |
|
|
DateChooser |
Displays a full month of days to let you select a date. |
|
|
DateField |
Displays the date with a calendar icon on its right side. When a user clicks anywhere inside the control, a DateChooser control pops up and displays a month of dates. |
|
|
HorizontalList |
Displays a horizontal list of items. |
|
|
HRule/VRule |
Displays a single horizontal rule (HRule) or vertical rule (VRule). |
|
|
HSlider/VSlider |
Lets users select a value by moving a slider thumb between the end points of the slider track. |
|
|
Image |
Imports GIF, JPEG, PNG, SVG, and SWF files. |
|
|
Label |
Displays a noneditable single-line field label. |
|
|
LinkBar |
Displays a horizontal row of LinkButton controls that designate a series of link destinations. |
|
|
LinkButton |
Displays a simple hypertext link. |
|
|
List |
Displays a scrollable array of choices. |
|
|
Menu |
Displays a pop-up menu of individually selectable choices, much like the File or Edit menu of most software applications. |
|
|
MenuBar |
Displays a horizontal menu bar that contains one or more submenus of Menu controls. |
|
|
NumericStepper |
Displays a dual button control that you can use to increase or decrease the value of the underlying variable. |
|
|
ProgressBar |
Provides visual feedback of how much time remains in the current operation. |
|
|
RadioButton |
Displays a set of buttons of which exactly one is selected at any time. |
|
|
RadioButton Group |
Displays a group of RadioButton controls with a single click event listener. |
|
|
RichTextEditor |
Includes a multiline editable text field and controls for specifying text formatting. |
|
|
ScrollBar (HScrollBar and VScrollBar) |
Displays horizontal and vertical scroll bars. |
|
|
SWFLoader |
Displays the contents of a specified SWF file or JPEG file. |
|
|
TabBar |
Displays a horizontal row of tabs. |
|
|
Text |
Displays a noneditable multiline text field. |
|
|
TextArea |
Displays an editable text field for user input that can accept more than a single line of input. |
|
|
TextInput |
Displays an editable text field for a single line of user input. Can contain alphanumeric data, but input is interpreted as a String data type. |
|
|
TileList |
Displays a tiled list of items. The items are tiled in vertical columns or horizontal rows. |
|
|
ToggleButtonBar |
Displays a row of related buttons with a common appearance. |
|
|
Tree |
Displays hierarchical data arranged as an expandable tree. |
|
|
VideoDisplay |
Incorporates streaming media into Flex applications. |