2 Replies Latest reply on Jul 9, 2007 9:59 PM by Rothrock

    for loop help needed

    aaronlyon
      How do I simplify this:

      _root.btn1._visible = false;
      _root.btn2._visible = false;
      _root.btn3._visible = false;

      with a for loop like this:

      for (i=1; i<=modtotal; i++) {
      }
        • 1. for loop help needed
          I would think:
          • 2. Re: for loop help needed
            Rothrock Level 5
            Almost.

            _root["btn"+i]._visible=false;

            The sample given would look inside the object called btn for items named 1, 2, and 3 (asuming modtotal was equal to 3). The two things wrong with that are there isn't an object called btn and even if there was you cannot give objects names that are simply numbers.

            I say "objects" because this array access technique works with movieclips, buttons, variables, functions, etc. So it is one of the best tricks in your aresnal.