3 Replies Latest reply on Nov 20, 2010 7:40 PM by Ned Murphy

    Repeat small bit of code 1-100 hundred times with each code having different instance name?

    prodigalmaster Level 2

      Hi, here's a part of my code:

       

      player_mc.onEnterFrame = function() {

           if (enemy0.hitTest(this)) {

                enemy0.speed = 0;

           } else {

                enemy0.speed = 1;

           }

          if (enemy1.hitTest(this)) {

                enemy1.speed = 0;

           } else {

           enemy1.speed = 1;

           }

      };

       

      Note the red code, I need to repeat this an unknown amount yet multiple times but with the number on the end of enemy incremented by 1 each time. It starts with 0 as you can see the code just above the red. I heard about for loops using 'i' but im unsure about how to use it. Please help and if possible explain. Thanks for reading And/Or replying.

       

      edit: ah, this forum isnt letting me highlight red. Everything in this editor is also failing. well, when I say code in red i mean this code:

      if (enemy1.hitTest(this)) {

                enemy1.speed = 0;

           } else {

           enemy1.speed = 1;

           }