7 Replies Latest reply on Aug 5, 2008 4:48 PM by kglad

    Change text color when typing begins (k)

    Level 7
      Is there a way in a dynamic text field that when typing begins the text
      in it changes to a certain color?

      I have an if statement that writes a warning in the field if a user has
      entered a negative number. It tells the user that numbers must be
      positive and displays this message in red.

      I want when the person begins to type over this warning for the text to
      go back to black.

      -Kirk
        • 1. Re: Change text color when typing begins (k)
          Level 7
          Also is there a way that when a user places their cursor in the field it
          highlights everything in it? So that when they return to the field with
          the warning to re-enter their number, they can just start typing and the
          text will be black and the warning will be gone?

          -kirk




          W. Kirk Lutz wrote:
          > Is there a way in a dynamic text field that when typing begins the text
          > in it changes to a certain color?
          >
          > I have an if statement that writes a warning in the field if a user has
          > entered a negative number. It tells the user that numbers must be
          > positive and displays this message in red.
          >
          > I want when the person begins to type over this warning for the text to
          > go back to black.
          >
          > -Kirk
          • 2. Re: Change text color when typing begins (k)
            kglad Adobe Community Professional & MVP
            yes, check the Selection class to select text and you can use setTextFormat() and the textformat class to control font color.
            • 3. Re: Change text color when typing begins (k)
              Level 7
              You're going to need to dumb this down to me. I am self taught in
              ActionScript so I'm not well versed in terms like Selection class and such.

              -kirk



              kglad wrote:
              > yes, check the Selection class to select text and you can use setTextFormat() and the textformat class to control font color.
              • 4. Re: Change text color when typing begins (k)
                kglad Adobe Community Professional & MVP
                if tf is your textfield instance name, you can use:

                • 5. Re: Change text color when typing begins (k)
                  Level 7
                  Woohoo!

                  It worked. Now I just need to put it on the other two fields and this
                  puppy is done.

                  Thanks,
                  -kirk



                  kglad wrote:
                  > if tf is your textfield instance name, you can use:
                  >
                  >
                  >
                  > var tfor:TextFormat=new TextFormat();
                  > tfor.color = 0x000000;
                  >
                  > var tl:MovieClip = this;
                  > tf.onSetFocus = function(of) {
                  > tl.onMouseUp=selectF;
                  > };
                  >
                  > function selectF(){
                  > tl.onMouseUp=null;
                  > Selection.setFocus(tf);
                  > Selection.setSelection(0,tf.text.length);
                  > tf.setNewTextFormat(tfor);
                  > }
                  >
                  • 6. Re: Change text color when typing begins (k)
                    Level 7
                    Works for one, but not for all.

                    When I put it in for each it always wants to select the last field.
                    There are three fields. Each needs this functionality.

                    I think it has to do with the onMouseUp part. The mouse button goes up
                    an it selects the last of the three commands.

                    The text fields are setup as Input Text, not MovieClips.

                    -Kirk





                    W. Kirk Lutz wrote:
                    > Woohoo!
                    >
                    > It worked. Now I just need to put it on the other two fields and this
                    > puppy is done.
                    >
                    > Thanks,
                    > -kirk
                    >
                    >
                    >
                    > kglad wrote:
                    >> if tf is your textfield instance name, you can use:
                    >>
                    >>
                    >>
                    >> var tfor:TextFormat=new TextFormat();
                    >> tfor.color = 0x000000;
                    >>
                    >> var tl:MovieClip = this;
                    >> tf.onSetFocus = function(of) {
                    >> tl.onMouseUp=selectF;
                    >> };
                    >>
                    >> function selectF(){
                    >> tl.onMouseUp=null;
                    >> Selection.setFocus(tf);
                    >> Selection.setSelection(0,tf.text.length);
                    >> tf.setNewTextFormat(tfor);
                    >> }
                    >>
                    • 7. Re: Change text color when typing begins (k)
                      kglad Adobe Community Professional & MVP
                      that code will work for multiple textfields. you just need to use the currently selected textfield as a parameter in selectF() or use different selectF functions for the different textfields.