4 Replies Latest reply on May 24, 2006 7:48 AM by Newsgroup_User

    trace(this["count"+ii]); returns undefined within function

    ChrisFlynn
      So I have a function that looks like this.

      fu = function () {
      var count1 = 0;
      var count2 = 0;
      var count3 = 0;
      for (var ii = 1; ii<=3; ii++) {
      trace(this["count"+ii]);
      }
      };

      when it runs it returns

      undefined
      undefined
      undefined

      However,when I declare the variables outside that function, like this:

      var count1 = 0;
      var count2 = 0;
      var count3 = 0;
      fu = function () {

      for (var ii = 1; ii<=3; ii++) {
      trace(this["count"+ii]);
      }
      };

      it returns:

      0
      0
      0

      Which is what i want, but I need those variables declared locally. SO WHY DOESNT IT WORK THE OTHER WAY????

      Someone please help me, because I'm obviously missing something.

      Thanks
      Chris