Using ActionScript 3.0 Components |
|
|
|
| Using the UI Components > Using the NumericStepper > Creating an application with the NumericStepper | |||
The following procedure explains how to add a NumericStepper component to an application while authoring. The example places a NumericStepper component and a Label component on the Stage and creates a listener for an Event.CHANGE event on the NumericStepper instance. When the value in the numeric stepper changes, the example displays the new value in the text property of the Label instance.
To create an application with the NumericStepper component:
import flash.events.Event;
aLabel.text = "value = " + aNs.value;
aNs.addEventListener(Event.CHANGE, changeHandler);
function changeHandler(event:Event) :void {
aLabel.text = "value = " + event.target.value;
};
This example sets the text property of the label to the value of the NumericStepper. The changeHandler() function updates the label's text property whenever the value in the NumericStepper instance changes.
The following example creates three NumericSteppers with ActionScript code, one each for entering the month, day, and year of the user's date of birth. It also adds Labels for a prompt and for identifiers for each of the NumericSteppers.
To create a NumericStepper using ActionScript:import fl.controls.Label; import fl.controls.NumericStepper; var dobPrompt:Label = new Label(); var moPrompt:Label = new Label(); var dayPrompt:Label = new Label(); var yrPrompt:Label = new Label(); var moNs:NumericStepper = new NumericStepper(); var dayNs:NumericStepper = new NumericStepper(); var yrNs:NumericStepper = new NumericStepper(); addChild(dobPrompt); addChild(moPrompt); addChild(dayPrompt); addChild(yrPrompt); addChild(moNs); addChild(dayNs); addChild(yrNs); dobPrompt.setSize(65, 22); dobPrompt.text = "Date of birth:" dobPrompt.move(80, 150); moNs.move(150, 150); moNs.setSize(40, 22); moNs.minimum = 1; moNs.maximum = 12; moNs.stepSize = 1; moNs.value = 1; moPrompt.setSize(25, 22); moPrompt.text = "Mo."; moPrompt.move(195, 150); dayNs.move(225, 150); dayNs.setSize(40, 22); dayNs.minimum = 1; dayNs.maximum = 31; dayNs.stepSize = 1; dayNs.value = 1; dayPrompt.setSize(25, 22); dayPrompt.text = "Day"; dayPrompt.move(270, 150); yrNs.move(300, 150); yrNs.setSize(55, 22); yrNs.minimum = 1900; yrNs.maximum = 2006; yrNs.stepSize = 1; yrNs.value = 1980; yrPrompt.setSize(30, 22); yrPrompt.text = "Year"; yrPrompt.move(360, 150);
|
|
|
|