2 Replies Latest reply on Jan 13, 2009 12:10 AM by FlashMonkey666

    Is there an "exit repeat" command

    FlashMonkey666 Level 1
      I'm using a "for" command, like below to do a repeat loop. But I want the repeat loop to exit if certain conditions are met.

      My script will be something like the following. I want the whole repeat loop to stop as soon as the line "_root.mov = ("stop");" How do I do that?
      Thank you

      if (_root.mov == "up") {
      _y -= _root.speed;
      for (var i = 0; i<(_root.speed); i++) {
      if (walls.hitTest(_x, ((getBounds(_root).yMax)-i), true)) {
      _root.mov = ("stop");
      _y += i;
      }
      }
      }
        • 1. Re: Is there an &quot;exit repeat&quot; command
          Level 7
          FlashMonkey666,

          > I'm using a "for" command, like below to do a repeat loop.
          > But I want the repeat loop to exit if certain conditions are met.

          You'll want to check into the "break" statement. Here's a quick listing
          from the AS2 docs:

          "Appears within a loop (for , for..in, do..while or while) or within a block
          of statements associated with a particular case within a switch statement.
          When used in a loop, the break statement instructs Flash to skip the rest of
          the loop body, stop the looping action, and execute the statement following
          the loop statement."

          ... but it also exists in AS3 (if that's what you're using) and does the
          same thing.


          David Stiller
          Adobe Community Expert
          Dev blog, http://www.quip.net/blog/
          "Luck is the residue of good design."


          • 2. Re: Is there an &quot;exit repeat&quot; command
            FlashMonkey666 Level 1
            Thanks! So would I just say
            break;

            ?

            Incidently, is there a way to break the whole handler, like
            exit(enterframe); ??
            or break(enterframe) ?

            thanks