O'Reilly logo

Actionscript Cookbook by Joey Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

11.10. Adding Checkboxes to a Form

Problem

You want to add checkboxes to your form.

Solution

Use checkbox UI components.

Discussion

You should use checkboxes in situations in which you want a user to be able to select multiple options from a list, but you do not wish to use a list box. Or, alternatively, you should use a checkbox in any situation that calls for a simple yes/no or true/false answer. Checkboxes function similarly to radio buttons, except for a few important distinctions:

  • You cannot set a data value for a checkbox. Checkboxes have only two possible values: true (checked) or false (unchecked).

  • Checkboxes do not have a natively available group as radio buttons do.

  • Multiple checkboxes should not be used for mutually exclusive choices.

You can set the label of a checkbox with the setLabel( ) method, and you can set the placement of the label (right or left) using the setLabelPlacement( ) method, just as with radio buttons.

The fact that checkboxes don’t provide native support for grouping, as radio buttons do, is not necessarily a problem. However, by adding grouping functionality to checkboxes (and coding the checkbox group class to inherit from the radio button group class), you can easily leverage the resizing and positioning code from Recipe 11.7 and Recipe 11.8 for radio button groups to work with checkboxes.

You can create a custom checkbox group class as follows:

  1. Create a FCheckBoxGroupClass constructor.

  2. Designate FCheckBoxGroupClass to inherit from FRadioButtonGroupClass ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required