3 Replies Latest reply on Oct 10, 2007 11:04 PM by kglad

    While and If Statements

    DJ_Sick_Nick Level 1
      I have the code:

      while (_parent.orangehold == 1) {
      if (this.hitTest(_parent.orange.active)) { //I think this is what's making Flash crash when I export as SWF
      gotoAndPlay ("hold");
      }
      }
      if (this.hitTest(_parent.orange.active)) { //Here I want to make is so that if the while loop isnt true then it uses this.
      gotoAndPlay ("hit");
      }

      How can I do that without Flash crashing on me?
        • 1. Re: While and If Statements
          kglad Adobe Community Professional & MVP
          don't create endless loops.

          for checking a hitTest() you can't use a for-loop and you can't use a while-loop: they execute from beginning to end (if you have an end) before anything is updated on-stage.

          use an onEnterFrame or setInterval loop to repeatedly check your hitTest.

          and it doesn't make sense to have two identical if-statements (with different consequences, no less).
          • 2. Re: While and If Statements
            DJ_Sick_Nick Level 1
            Wow I didnt think of that.... how stupid of me. Now that I have that working, I ran across another error of my terible common sense. Can you please tell me what's wrong with this??

            onClipEvent (keyDown) {
            if (Key.isDown(65)) {
            this.gotoAndStop (2);
            }else if (Key.isDown(65) and Key.isDown(Key.SPACE)) {
            this.gotoAndPlay (3);
            }
            }
            onClipEvent (keyUp) {
            this.gotoAndStop (1);
            }
            • 3. Re: While and If Statements
              kglad Adobe Community Professional & MVP
              use && instead of and in if-statements.

              the keyUp event can be missed if more than one key is pressed simultaneously.