To create and use a custom validator class:
1.
In Flash, create a new ActionScript (AS) file.
2.
Add the following code to the AS file:
class OddNumbersOnly extends mx.data.binding.CustomValidator
{
public function validate(value) {
// make sure the value is of type Number
var n = Number(value);
if (String(n) == "NaN") {
this.validationError("'" + value + "' is not a number.");
return;
}
// make sure the number is odd
if (n % 2 == 0) {
this.validationError("'" + value + "' is not an odd number.");
return;
}
// data is OK, no need to do anything, just return
}
}
3.
Save the AS file as OddNumbersOnly.as.
The name of the AS file must match the name of the class.
4.
Create a new Flash (FLA) file.
5.
Open the Components panel.
6.
Drag a NumericStepper component from the Components panel to the Stage and name
it stepper.
7.
Drag a Label component to the Stage and name it textLabel.
8.
Drag a TextArea component to the Stage and name it status.
9.
Select the NumericStepper component, and open the Component inspector.
10.
Select the Bindings tab in the Component inspector, and click the Add Binding (+) button.
11.
Select the Value property (the only one) in the Add Bindings dialog box, and click OK.
12.
In the Component inspector, double-click Bound To in the Binding Attributes pane of the
Bindings tab to open the Bound To dialog box.
13.
In the Bound To dialog box, select the Label component in the Component Path pane and
its
property in the Schema Location pane. Click OK.
text
14.
Select the Label component on the Stage, and click the Schema tab in the Component
inspector.
218
Data binding classes (Flash Professional only)
Need help?
Do you have a question about the FLASH 8-COMPONENTS LANGUAGE and is the answer not in the manual?
Questions and answers