Input Textfield

I am new to Actionscript 3. How do I write code for this: I want to restrict the text input to numbers 0-9 (no alphabet letters allowed).
aceKayAsked:
Who is Participating?
 
liamrichardsCommented:
You want something like this:


package {

  import flash.display.Sprite;
  import flash.text.TextField;
  public class Main extends Sprite {
    public function Main(  ) {
      var field:TextField = new TextField(  );
      field.type = flash.text.TextFieldType.INPUT;
      field.border = true;
      field.background = true;        
      field.restrict = "0-9";  
      addChild(field);
    }
  }
}
0
 
aceKayAuthor Commented:
I found this code that worked for me


var theTextField:TextField = new TextField();
theTextField.type = TextFieldType.INPUT;
theTextField.border = true;
theTextField.x = 20;
theTextField.y = 107;
theTextField.scaleX = .2
theTextField.scaleY = .35
theTextField.multiline = false;
theTextField.wordWrap = false;
theTextField.restrict = "0-9"; 
theTextField.defaultTextFormat = Field;
addChild(theTextField);

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.