1 Reply Latest reply on Dec 11, 2006 3:37 PM by Rothrock

    loops

    sk8morestudyless Level 1
      ok im having this problem
      i hate puting actions on the frame so is there any way i can edit this code for an infinite looping of enemys into the mc

      the code is

      ec=5
      for(i=1; i<=ec; i++){
      _root.enemy..duplicateMovieClip("enemy"+i,i)
      }
        • 1. Re: loops
          Rothrock Level 5
          An infinite amount of enemies sounds like an awful lot! :) And Flash only gives you a couple million depths you can put things on so you will run out long before you get to infinite.

          So I'm not sure exactly what you are trying to do, but maybe something like this.

          curCount=0;
          enemyPerTurn=5;
          enemyDelay=500;

          function deployEnemy(){
          for(i=0;i<enemyPerTurn;i++){
          _root.enemy.duplicateMovieClip("enemy"+curCount,curCount);
          curCount++
          }

          enemyInterval=setInterval(deployEnemy,enemyDelay);


          I've just made that up off the top of my head and haven't tested it. But it should (more or less) deploy however many enemies you want per turn every delay interval (in milliseconds). So as it stands it would deploy 5 enemies every 1/2 second. When you wanted it to stop you would do:

          clearInterval(enemyInterval);

          Also there is that limit on the number of depths. It will take a long time to use them all up, but between Levels or when starting a new life or what have you, you might want to recent the curCount back to zero or something like that.