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 ...

Get Actionscript 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.