1 Reply Latest reply on Jan 11, 2008 8:39 AM by camfieldaj

    for loop....


      i have this code within the CDATA in my .mxml document:

      for (var i:int=1; i<100; i++)
      var randomNum:int = Math.floor(Math.random()*101);
      setTimeout(i++ ,2000);

      and for both instances of "i" i have the error message "Access of undefined property i."

      I'm confused to why it thinks it is undefined, what am I doing wrong?

        • 1. Re: for loop....
          camfieldaj Level 1
          It's most probably a scoping issue. Since you have your code just sitting in the CDATA brackets, the compiler doesn't know what you're trying to do. If you do this:


          private function setTime():void
          var cnt:int = 1;
          var randomNum:int = Math.floor(Math.random()*101);
          var ST:int;

          for (cnt=1; cnt<100; cnt++)
          ST = cnt + 2000;


          it compiles without errors.


          Andy C.(never #)