1 Reply Latest reply on Jun 16, 2009 8:28 PM by kglad

    How to restrict characters in a dynamic text field?

    atrzebunia

      The following code does what I want (i.e. any key I press on the keyboard displays the character in uppercase format in the dynamic field on the stage) except that it does not properly restrict the characters to A-Z and 0-9.  I can still press the <,.>?!/ keys and each of these chars shows up in the dynamic text field.  My dynamic text field is txt_Box.  What is wrong with the following code?

       

      var varKeyListener:Object = new Object();
      varKeyListener.onKeyDown = function()
      {
          txt_Box.restrict = "A-Z 0-9";
          txt_Box.text = String.fromCharCode(Key.getAscii());
          txt_Box.text = txt_Box.text.toUpperCase();
      }

       

      Key.addListener(varKeyListener);

       

      Thanks in advance for any help anyone can provide.

        • 1. Re: How to restrict characters in a dynamic text field?
          kglad Adobe Community Professional & MVP

          text added to a textfield via actionscript is not subject to your restict property. use:

           


           

          var varKeyListener:Object = new Object();

          var s:String="ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789"
          varKeyListener.onKeyDown = function()
          {

          if(s.indexOf(String.fromCharCode(Key.getAscii()))>-1){

              txt_Box.restrict = "A-Z 0-9";
              txt_Box.text = String.fromCharCode(Key.getAscii());
              txt_Box.text = txt_Box.text.toUpperCase();

          }
          }

           

          Key.addListener(varKeyListener);