4 Replies Latest reply on Apr 9, 2008 1:54 PM by yogi bear

    Loop Problem

    yogi bear Level 1
      This loop only generate 3 rows across and 3 down instead of 4 across. I can't find the problem.
      Does something happen when the counter reaches 10? Any ideas?

      function buildResMenu(){
      var xSpacing:Number = 130;
      var ySpacing:Number = 20;
      var xStart:Number = 200;
      var yStart:Number = 520;
      var count:Number = 0;
      for (i=1; i<4; i++) {
      for(j=0; j<3; j++) {
      count++;
      var name:String = "menuTwo" + count + "_mc";
      _root.m2.attachMovie("flipper", name, count);
      _root.m2[name]._x = ((i * xSpacing) + xStart) - 130;
      _root.m2[name]._y = (j * ySpacing) + yStart;
      _root.m2[name].main_text.text = resMenu[count-1][0];
      _root.m2[name].projectID = resMenu[count-1][1];

      if (count > resMenu.length){
      _root.m2[name]._visible = false;
      }

      _root.m2[name].item_btn.onPress = function () {
      itemProjectClicked (this._parent.projectID);

      }

      }
      }
      }


      ;

        • 1. Re: Loop Problem
          FlashTastic Level 1
          The problem is with your i loop.

          Your condition is that i<4. Since i starts at 1 the loop will only run 3 times. You either need to start i as 0, or use i<=4.

          Cheers,
          FlashTastic
          • 2. Re: Loop Problem
            yogi bear Level 1
            Flash Tastic

            I tried that and I get the same problem as I do if I make i<5. The 3 rows of three are fine and then I get an instant(s) of the attached buttons at 0,0 in the frame. I'm totally baffled. There are 12 items in the array and it reads 9 of them if
            I make it 3 across and 4 down instead of the total 12 it should read.
            • 3. Re: Loop Problem
              FlashTastic Level 1
              In your current code, if you do a quick trace of the count variable, you'll see that it only gets to 9, which is why only 9 items are being read from the array. Set a break point at the top of your function and use the debugger to step through each iteration of the loop, that way you should be able to see where things go wrong in regards to positioning.

              Cheers,
              FlashTastic
              • 4. Re: Loop Problem
                yogi bear Level 1
                Flash Tastic,

                Good idea. You see the problem. I'll give it a try. Thanks for your help.

                YB