ActionScript 2.0 Components Language Reference |
|
|
|
| ComboBox component > ComboBox.restrict | |||
Flash Player 6 (6.0.79.0).
Flash MX 2004.
comboBoxInstance.restrict
Property; indicates the set of characters that a user can enter in the text field of a combo box. The default value is undefined. If this property is null or an empty string (""), a user can enter any character. If this property is a string of characters, the user can enter only characters in the string; the string is scanned from left to right. You can specify a range by using a
dash (-).
If the string begins with a caret (^), all characters that follow the caret are considered unacceptable characters. If the string does not begin with a caret, the characters in the string are considered acceptable.
You can use the backslash (\) to enter a hyphen (-), caret (^), or backslash (\) character, as shown here:
\^ \- \\
When you enter a backslash in the Actions panel within double quotation marks, it has a special meaning for the Actions panel's double-quote interpreter. It signifies that the character following the backslash should be treated "as is." For example, you could use the following code to enter a single quotation mark:
var leftQuote = "\'";
The Actions panel's restrict interpreter also uses the backslash as an escape character. Therefore, you may think that the following should work:
myText.restrict = "0-9\-\^\\";
However, since this expression is surrounded by double quotation marks, the value 0-9-^\ is sent to the restrict interpreter, and the restrict interpreter doesn't understand this value.
Because you must enter this expression within double quotation marks, you must not only provide the expression for the restrict interpreter, but you must also escape the expression so that it will be read correctly by the Actions panel's built-in interpreter for double quotation marks. To send the value 0-9\-\^\\ to the restrict interpreter, you must enter the following code:
myCombo.restrict = "0-9\\-\\^\\\\";
The restrict property restricts only user interaction; a script may put any text into the text field. This property does not synchronize with the Embed Font Outlines check boxes in the Property inspector.
With a ComboBox component instance my_cb, the following ActionScript restricts the entry of characters to numbers 0-9, dashes, and dots:
// Add Items to List.
my_cb.addItem({data:1, label:"First Item"});
my_cb.addItem({data:2, label:"Second Item"});
// Enable editing of combo box.
my_cb.editable = true;
// Restrict the characters that can be entered into combo box.
my_cb.restrict = "0-9\\-\\.\\ ";
In the following example, the first line of code limits the text field to uppercase letters, numbers, and spaces. The second line of code allows all characters except lowercase letters.
my_combo.restrict = "A-Z 0-9"; my_combo.restrict = "^a-z";
The following code allows a user to enter the characters "0 1 2 3 4 5 6 7 8 9 - ^ \" in the instance myCombo. You must use a double backslash to escape the characters -, ^, and \. The first \ escapes the double quotation marks, and the second \ tells the interpreter that the next character should not be treated as a special character.
myCombo.restrict = "0-9\\-\\^\\\\";
|
|
|
|