4 Replies Latest reply on Oct 11, 2006 1:51 AM by nITiNkIlLeRmEeRuT

    Setting the length of a Text Field

    indiansoil
      I have a Text Field which gets values from the user and I want to set the character-limit, say 10, so that it can accept and display a maximum of 10 characters only.

      How to achive it?
        • 1. Re: Setting the length of a Text Field
          crazyjoemilan Level 2
          There is an option for this in the preferences panel when you create an input text field. If you're looking for action script to bar an amount of characters from entering a field, you'll just want to look at any basic String tutorials.
          • 2. Setting the length of a Text Field
            nITiNkIlLeRmEeRuT Level 1
            _txt.maxChars = 10;

            replace _txt with the instance name of the textfield
            • 3. Re: Setting the length of a Text Field
              indiansoil Level 1
              HI!

              Thanks for your support!

              Well, it works only when I type in the Text Field via the keyboard in that case the Text Field is of Input type of field.

              But when I am using a Text Field which is Dynamic and it recieves its value from a variable attached to it. I have to type nothing in the Text Field because it's a Dynamic Text Field.

              //variable vTxt is attached to the Text Field txt
              var vTxt:String = " ";
              this._root.txt.maxChars = 2; //the text field txt must store only 2 characters
              this._root.vTxt = "INDIA"; //here INDIA is the value assigned to the variable vTxt which is attached to the text field txt

              If I remove the last statement, it will work but only when the Text Field is INPUT Type of Field.
              • 4. Re: Setting the length of a Text Field
                nITiNkIlLeRmEeRuT Level 1
                [code]
                //variable vTxt is attached to the Text Field txt
                _root.vTxt.maxChars = 2; //the text field txt must store only 2 characters
                _root.vTxtText = "INDIA"; //here INDIA is the value assigned to the variable vTxt which is attached to the text field txt

                _root.vTxt.text = _root.vTxtText.substring(0,_root.vTxt.maxChars);
                [/code]
                where vTxt is instance name of textfield