User Guide
Using the CheckBox component 131
To create an application with the CheckBox component:
1. Drag two TextInput components from the Components panel to the Stage.
2. In the Property inspector, enter the instance names minimumAge and maximumAge.
3. Drag a CheckBox component from the Components panel to the Stage.
4. In the Property inspector, do the following:
■ Enter restrictAge for the instance name.
■ Enter Restrict Age for the label parameter.
5. Select Frame 1 in the Timeline, open the Actions panel, and enter the following code:
var restrictAgeListener:Object = new Object();
restrictAgeListener.click = function (evt:Object) {
minimumAge.enabled = evt.target.selected;
maximumAge.enabled = evt.target.selected;
};
restrictAge.addEventListener("click", restrictAgeListener);
This code creates a click event handler that enables and disables the minimumAge and
maximumAge text field components, which have already been placed on Stage. For more
information, see
CheckBox.click and “TextInput component” on page 1209.
To create a check box using ActionScript:
1. Drag the CheckBox component from the Components panel to the current document’s
library.
This adds the component to the library, but doesn’t make it visible in the application.
2. Drag the TextInput component from the Components panel to the current document’s
library.
3. In the first frame of the main Timeline, add the following ActionScript to the Actions panel
to create and position component instances:
this.createClassObject(mx.controls.CheckBox, "testAge_ch", 1,
{label:'Age Range', selected:true});
this.createClassObject(mx.controls.TextInput, "minimumAge_ti", 2,
{restrict:[0-9], text:18, maxChars:2});
minimumAge_ti.move(20, 30);
this.createClassObject(mx.controls.TextInput, "maximumAge_ti", 3,
{restrict:[0-9], text:55, maxChars:2});
maximumAge_ti.move(20, 60);
This script uses the method “UIObject.createClassObject()” on page 1362 to create the
CheckBox instance named restrictAge, and specifies a label property. Then, the code uses
the method “UIObject.move()” on page 1375 to position the button.