2 Replies Latest reply on Jul 20, 2007 8:49 AM by

    ("element"+ "A"+ String(i)+ String(j)).text = "1"

      Hi all,

      I have developed a 3x3 Matrix through the IDE. The Matrix elements (Dynamic TextFields) are named elementA00, elementA01....
      I am trying to create a loop where the Dynamic TextFields are given a specific value at the beginning of my script, but I keep getting error messages that have to do with ("element"+ "A"+ String(i)+ String(j)).text = "1".

      Here is the problematic part of my script:
      var i:Number;
      var j:Number;
      for (i = 0; i<3; i++) {
      for (j = 0; j<3; j++) {
      if (i==j) { ("element"+ "A"+ String(i)+ String(j)).text = "1";}
      else { ("element"+ "A"+ String(i)+ String(j)).text = "0";}}}
      Is there a work around here?
      Please help. I am losing my mind over this.

      Thanks in advance!


        • 1. Re: (&quot;element&quot;+ &quot;A&quot;+ String(i)+ String(j)).text = &quot;1&quot;
          Level 7
          Hi Galateia,

          This part definitely looks problematic: "element"+ "A"+ String(i)+
          String(j)).text = "1";

          I could be wrong but I believe what you are trying to do is evaluate
          elements by name. This is done through the array access operator (using
          square brackets). Here is what I *think* you're trying to achieve, along
          with removal of some redundancy which seems to be there:
          var i:Number;
          var j:Number;
          for (i = 0; i<3; i++) {
          for (j = 0; j<3; j++) {
          if (i==j) { this["elementA"+ String(i)+ String(j)].text = "1";}
          else { this["elementA"+ String(i)+ String(j)].text = "0";}}}

          Note that I concatenated the "element" and "A" since these don't seem
          to ever change. Also, I'm assuming that the text fields are all stored
          in 'this'. If that's not the case, you'll need to change 'this' to the
          containing object/clip/etc.

          Regards,
          Patrick


          Galateia wrote:
          > Hi all,
          >
          > I have developed a 3x3 Matrix through the IDE. The Matrix elements (Dynamic
          > TextFields) are named elementA00, elementA01....
          > I am trying to create a loop where the Dynamic TextFields are given a specific
          > value at the beggining of my script, but I keep getting error messages that
          > have to do with ("element"+ "A"+ String(i)+ String(j)).text = "1".
          >
          > Here is the problematic part of my script:
          > var i:Number;
          > var j:Number;
          > for (i = 0; i<3; i++) {
          > for (j = 0; j<3; j++) {
          > if (i==j) { ("element"+ "A"+ String(i)+ String(j)).text = "1";}
          > else { ("element"+ "A"+ String(i)+ String(j)).text = "0";}}}
          >
          >
          >
          >

          --
          http://www.baynewmedia.com
          Faster, easier, better...ActionScript development taken to new heights.
          Download the BNMAPI today. You'll wonder how you ever did without it!
          Available for ActionScript 2.0/3.0.
          • 2. Re: (&quot;element&quot;+ &quot;A&quot;+ String(i)+ String(j)).text = &quot;1&quot;
            You saved my day!

            Thank you,
            Galateia