There are four basic button types of controls: Button
, LinkButton
, RadioButton
, and CheckBox
. Although each type behaves similarly, they have different
intended uses. Figure 7-2 shows instances of
each type.
Of the four types, Button
and
LinkButton
are the most similar in use.
In fact, the primary difference between Button
and LinkButton
is purely cosmetic: buttons have
borders and backgrounds and link buttons do not. However, you’ll typically
use both types for similar purposes—generally to initiate some behavior
when the user clicks on the button or link button. Buttons are typically
more common than link buttons.
By default, buttons and link buttons respond to every click in the
same way. However, you can set the toggle
property of a button or link button to
true
, in which case the button will
have two states—selected and deselected—and it will toggle between those
states each time the user clicks it.
Radio buttons are quite different in use from standard buttons.
Radio buttons are typically used in groups. Radio buttons can be selected
or deselected, and only one button can be selected per group. For this
reason, radio buttons are often used when you want to allow the user to
select just one from a group of options. You should typically first create
a RadioButtonGroup
instance when using radio buttons. Then, assign the ID of the group
to the groupName
property of each radio
button in the group, as shown here:
<mx:RadioButtonGroup id="exampleGroup" /> <mx:RadioButton groupName="exampleGroup" label="A" value="a" /> <mx:RadioButton groupName="exampleGroup" label="B" value="b" />
Checkboxes are also buttons. They are most similar to standard
buttons that have been set to toggle. When a user clicks a checkbox, it
toggles the selected state of the component (toggling the value of the
selected
property). The following
creates a checkbox with a label of A
and toggled to selected
:
<mx:CheckBox id="exampleCheckbox" label="A" selected="true" />