3 Replies Latest reply on Mar 26, 2008 2:43 PM by collosal-G

    Field Text loop

    collosal-G
      Hi all,

      I am trying to make a loop that will change the properties of 8 input text fields. I have created the loop below, but it doesn't work:

      for (i = 1; i<= _root.fieldNumber; i++) {
      theField = "input" + i +"_txt";
      this[theField].onSetFocus = function () {
      this[theField].text = "";
      this[theField].textColor = 0x7F7F7F;
      }
      }

      I am trying to avoid having to create code for each text area like this for each separate field object:

      this.input1_txt.onSetFocus = function () {
      input1_txt.text = "";
      input1_txt.textColor = 0x7F7F7F;
      }

      Any suggestions on what I am doing wrong?

      Thanks,
      cg
        • 1. Re: Field Text loop
          robdillon Most Valuable Participant
          Do you get an error, or is that the textfields just don't lose their text? If you just get nothing as the result of the code, then you'll have to test for the usual suspects. Trace the value of _root.fieldNumber, the result of this[theField]. A trace in the function will tell you whether the function is actually running or not.
          • 2. Re: Field Text loop
            collosal-G Level 1
            Thanks Rob, for the quick reply.

            I did trace fieldNumber, and it's ok. When I hard code the process (as in the example below), it works as expected. I just don't want to use that much unnecessary code.

            One thing I did notice with a trace command to display "theField", it always comes back with input8_mc, no matter which field I click in. All the other values get overwritten.

            this.input1_txt.onSetFocus = function () {
            input1_txt.text = "";
            input1_txt.textColor = 0x7F7F7F;
            }

            this.input2_txt.onSetFocus = function () {
            input2_txt.text = "";
            input2_txt.textColor = 0x7F7F7F;
            }

            etc...
            • 3. Re: Field Text loop
              collosal-G Level 1
              OK. I got it. This code works.

              for (i = 1; i<= _root.fieldNumber; i++) {
              theField = this["input" + i +"_txt"];
              theField.onSetFocus = function () {
              this.text = "";
              this.textColor = 0x7F7F7F;
              trace (theField);
              }
              }

              Thanks, Rob for the help. It actually got me thinking on the right track. And thanks to Andrew for the offline help.

              cg