Restricting which characters a user can type into a TextInput component in Flash using ActionScript 3.0

by Peter deHaan on December 22, 2008

in TextInput

The following example shows how you can control which characters a user can type into a Flash ActionScript 3.0 TextInput control by setting the restrict property.

Full code after the jump.

// ActionScript 3.0
/* Requires:
 * - TextInput component in Flash library
 */
import fl.controls.TextInput;
 
var textInput:TextInput = new TextInput();
textInput.restrict = "0-9.";
textInput.move(10, 10);
addChild(textInput);

{ 1 comment… read it below or add one }

1 fernando 11.09.09 at 4:06 pm

hi, I`m doing a project for the uni and I need to restrict fields just for letters in these fields.
The code below show how I`m doing. This is not working. I`d like to know what is missing.
Thanks

if (checkBox.selected==true) {
chvalue_txt.text=newAmount.toFixed(2);
interestPayable = (newAmount + loanAmount)* loanTerm * rateA;
totalPayable = (newAmount + loanAmount + interestPayable);
mnthlyPayment = totalPayable/(loanTerm * 12);
firstName=(firstName_txt.text);
firstName_txt.restrict=”A-z”;
surName=(surName_txt.text);
surName_txt.restrict=”A-z”;
rate_txt.text=rate.toFixed(2);
interestPayable_txt.text=”£ “+interestPayable.toFixed(2);
totalPayable_txt.text=”£ “+totalPayable.toFixed(2);
mnthlyPayment_txt.text=”£ “+mnthlyPayment.toFixed(2);
} else if (checkBox.selected==false) {
chvalue_txt.text=”";
}
trace(checkbox);
}

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Previous post:

Next post: