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;
}
}
Save the ActionScript file as NumberFormatter.as.
3.
Create a new Flash (FLA) document.
4.
From the Components panel, drag a TextInput component to the Stage and name it textInput.
5.
Then drag a NumericStepper component to the Stage and name it stepper.
Open the Timeline and select the first frame on Layer 1.
6.
In the Actions panel, add the following code to the Actions panel:
7.
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 (
custom formatter class is included in the compiled SWF file.
Select Window > Panels > Other Panels > Classes to open the Classes library.
8.
Open your document's library by selecting Window > Library.
9.
Drag DataBindingClasses from the Classes library to your document's library.
10.
This makes the data binding runtime classes available for your document.
Save the FLA file to the same folder that contains NumberFormatter.as.
11.
Test the file (Control > Test Movie).
12.
Click the buttons on the NumericStepper component and watch the contents of the TextInput
component update.
218
Chapter 6: Components Dictionary
var x:NumberFormatter
) ensures that the byte code for your
Need help?
Do you have a question about the FLASH MX 2004-USING COMPONENTS and is the answer not in the manual?
Questions and answers