User Guide

218 Chapter 6: Components Dictionary
if (rawValue == numArray[i]) {
returnValue = strArray[i];
break;
}
}
return returnValue;
} // convert a formatted value, return a raw value
function unformat(formattedValue) {
var returnValue;
var strArray = new Array('one', 'two', 'three');
var numArray = new Array(1, 2, 3);
returnValue = "invalid";
for (var i = 0; i<strArray.length; i++) {
if (formattedValue == strArray[i]) {
returnValue = numArray[i];
break;
}
}
return returnValue;
}
}
3.
Save the ActionScript file as NumberFormatter.as.
4.
Create a new Flash (FLA) document.
5.
From the Components panel, drag a TextInput component to the Stage and name it textInput.
Then drag a NumericStepper component to the Stage and name it stepper.
6.
Open the Timeline and select the first frame on Layer 1.
7.
In the Actions panel, add the following code to the Actions panel:
import mx.data.binding.*;
var x:NumberFormatter;
var customBinding = new Binding({component:stepper, property:"value",
event:"change"}, {component:textInput, property:"text",
event:"enter,change"}, {cls:mx.data.formatters.Custom,
settings:{classname:"NumberFormatter"}});
The second line of code (var x:NumberFormatter) ensures that the byte code for your
custom formatter class is included in the compiled SWF file.
8.
Select Window > Panels > Other Panels > Classes to open the Classes library.
9.
Open your document’s library by selecting Window > Library.
10.
Drag DataBindingClasses from the Classes library to your document’s library.
This makes the data binding runtime classes available for your document.
11.
Save the FLA file to the same folder that contains NumberFormatter.as.
12.
Test the file (Control > Test Movie).
Click the buttons on the NumericStepper component and watch the contents of the TextInput
component update.