11 Replies Latest reply on Dec 5, 2006 1:36 PM by kglad

    text input

    kerrimead Level 1
      I am new to flash. I am coming from a director background.

      I want to do something that is easy in director but I am not understanding it in Flash.

      I want to provide a text input and I want to only allow certain characters and I want to perform actions on certain characters. If I create a text input with the text tool, it seems I am not allowed to put actions on that object. If I use a text input component, I am stuck with a lot of default behavior I don't want. I have been able to write an on keypress function but it doesn't stop the default behavior. In director, you can catch the event first and then choose to pass on to the built in behavior or not.

      Can anyone tell me how to do this in Flash?

      And why can't I put behaviors on text boxes created with the text tool?
        • 1. Re: text input
          kglad Adobe Community Professional & MVP
          you can use the restrict property of textfields to restrict the characters allowed and you can use the onChanged property of textfields to detect when a user changes the text property of your textfield.
          • 2. Re: text input
            kerrimead Level 1
            Thanks for your reply.

            I tried restrict and it does part of what I want. My only problem with it is that I want the dash (-) character in the restrict string but it has a special meaning for 0-9 or a-z and so I can't make restrict recognize it as a character that I want to allow. Does that make sense? Do you know how to do that?
            • 3. Re: text input
              kglad Adobe Community Professional & MVP
              use the escape character (backslash) to designate a dash.
              • 4. Re: text input
                kerrimead Level 1
                Thanks again for the reply. I tried that and it didn't work but I tried again and I still can't get it to work.

                this.restrict = "0-9 +xX*=rR()//-";

                I want both the backslash and the dash to work. The backslash works but not the dash.

                Thanks
                • 5. Re: text input
                  kglad Adobe Community Professional & MVP
                  that code wouldn't allow a backslash (\). it allows a forward slash (/) and the last two characters do nothing.

                  backslash = \
                  forwardslash =/
                  • 6. Re: text input
                    kerrimead Level 1
                    Oops, my bad. I've been trying so many different things.

                    This is the one you think should work:
                    this.restrict = "0-9 /+xX*=rR()\-";

                    But it doesn't, sadly.
                    • 7. Re: text input
                      kglad Adobe Community Professional & MVP
                      you need to escape the escape character. use:

                      this.restrict = "0-9 /+xX*=rR()\\-";
                      • 8. text input
                        arunbe Level 1
                        You can use textFeild.onChanged functions to restrict your characters at the time of entering the values....
                        • 9. Re: text input
                          kerrimead Level 1
                          Thank you! That worked.

                          Could you answer the other question? When I create a text input field with the text tool, the actionscript editor windows says "current selection cannot have actions applied to it". I have to use a text input component. Is there really no way to apply actions to text input fields?

                          The only reason I want to use the text edit field instead of the the text input component is because I can't seem to get the font attributes to apply in the component. It will only use some default which looks like ariel pnt 9 or something.

                          Thanks for all of your time. I really appreciate it. I posted the same question yesterday on the general question forum and nobody answered.
                          • 10. Re: text input
                            kerrimead Level 1
                            Thanks, I am going to experiment with that. I think it will be the answer to the other problem I am having.
                            • 11. Re: text input
                              kglad Adobe Community Professional & MVP
                              that's correct, you cannot apply actions to a textfield. however, you can create a movieclip that contains a textfield and have all the functionality that you could desire (within the limitations of flash).

                              components are movieclips, so they can have actions applied to them. but they also carry quite a bit of extra baggage and are prone to cause problems.