Using ActionScript 3.0 Components |
|
|
|
| Using the UI Components > Using the CheckBox > Creating an application with the CheckBox | |||
The following procedure explains how to add a CheckBox component to an application while authoring, using an excerpt from a loan application form. The form asks if the applicant is a home owner and provides a CheckBox for the user to answer "yes." If so, the form presents two radio buttons for the user to indicate the relative value of the house.
To create an application with the CheckBox component:underRb.overRb.
homeCh.addEventListener(MouseEvent.CLICK, clickHandler);
underRb.enabled = false;
overRb.enabled = false;
function clickHandler(event:MouseEvent):void {
underRb.enabled = event.target.selected;
overRb.enabled = event.target.selected;
}
This code creates an event handler for a CLICK event that enables the underRb and overRb RadioButtons if the homeCh CheckBox is selected, and disables them if homeCh is not selected. For more information, see the MouseEvent class in the ActionScript 3.0 Language and Components Reference.
The following example duplicates the preceding application but creates the CheckBox and RadioButtons with ActionScript.
To create a CheckBox using ActionScript:This makes the components available to your application but does not put them on the Stage.
import fl.controls.CheckBox; import fl.controls.RadioButton; var homeCh:CheckBox = new CheckBox(); var underRb:RadioButton = new RadioButton(); var overRb:RadioButton = new RadioButton(); addChild(homeCh); addChild(underRb); addChild(overRb); underRb.groupName = "valueGrp"; overRb.groupName = "valueGrp"; homeCh.move(200, 100); homeCh.width = 120; homeCh.label = "Own your home?"; underRb.move(220, 130); underRb.enabled = false; underRb.width = 120; underRb.label = "Under $500,000?"; overRb.move(220, 150); overRb.enabled = false; overRb.width = 120; overRb.label = "Over $500,000?";
This code uses the CheckBox() and RadioButton() constructors to create the components and the addChild() method to place them on the Stage. It uses the move() method to position the components on the Stage.
homeCh.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(event:MouseEvent):void {
underRb.enabled = event.target.selected;
overRb.enabled = event.target.selected;
}
This code creates an event handler for the CLICK event that enables the underRb and overRb radio buttons if the homeCh CheckBox is selected, and disables them if homeCh is not selected. For more information, see the MouseEvent class in the ActionScript 3.0 Language and Components Reference.
|
|
|
|