5 Replies Latest reply on Apr 25, 2015 4:28 PM by kglad

    Piece of code doesn't play for CLICK animation

    joep1240785

      myHomeButton.addEventListener(MouseEvent.MOUSE_OVER, MouseOverHome);

      myHomeButton.addEventListener(MouseEvent.MOUSE_OUT, MouseLeavesHome);

       

       

      function MouseOverHome(MouseEvent): void {

        stopPlayReverse();

        homeHOMEanim.play();

      }

       

       

      function MouseLeavesHome(MouseEvent): void {

        this.addEventListener(Event.ENTER_FRAME, playReverse, false, 0, true);

      }

       

       

      function playReverse(Event): void {

        if (homeHOMEanim.currentFrame == 1) {

        stopPlayReverse();

        } else {

        homeHOMEanim.prevFrame();

        }

      }

       

       

      function stopPlayReverse(): void {

        if (this.hasEventListener(Event.ENTER_FRAME)) {

        this.removeEventListener(Event.ENTER_FRAME, playReverse);

        }

      }

       

       

      myHomeButton.addEventListener(MouseEvent.CLICK, ClickHome);

      function ClickHome(event: MouseEvent): void {

        if(homeHOMEanim.currentFrame >= 0 , homeHOMEanim.currentframe <=4){

        homeHOMEanim.gotoAndPlay(36);}

        if(homeHOMEanim.currentFrame >= 4 , homeHOMEanim.currentframe <=8){

        homeHOMEanim.gotoAndPlay(39);}

        if(homeHOMEanim.currentFrame >= 7 , homeHOMEanim.currentframe <=12){

        homeHOMEanim.gotoAndPlay(41);}

        if(homeHOMEanim.currentFrame >= 11 , homeHOMEanim.currentframe <=16){

        homeHOMEanim.gotoAndPlay(42);}

      }

       

      In this code, the top portion works perfectly (that is, everything before the addEventListener(MouseEvent.CLICK, ClickHome);), It acts so that when the mouse is over the home button, the animation starts. When the mouse leaves the button, the animation works in reverse back to the start.

      However, none of the last part of the code appears to work.

       

      Thankyou

        • 1. Re: Piece of code doesn't play for CLICK animation
          kglad Adobe Community Professional & MVP

          those if-statements are incorrectly formatted.  there's no such thing as a comma in an if-statement.

           

          if that's supposed to be an 'and', use &&.

           

          p.s. for completeness, if that's supposed to be an 'or' use ||

          • 2. Re: Piece of code doesn't play for CLICK animation
            joep1240785 Level 1

            To be fair, I had already tried the && instead of the commas before I tried the commas, I didn't think that part was ever going to work. But the same happens if they're like this:

             

            myHomeButton.addEventListener(MouseEvent.CLICK, ClickHome);

            function ClickHome(event: MouseEvent): void {

              if(homeHOMEanim.currentFrame >= 0 && homeHOMEanim.currentframe <=4){

              homeHOMEanim.gotoAndPlay(36);}

             

              if(homeHOMEanim.currentFrame >= 4 && homeHOMEanim.currentframe <=8){

              homeHOMEanim.gotoAndPlay(39);}

             

              if(homeHOMEanim.currentFrame >= 7 && homeHOMEanim.currentframe <=12){

              homeHOMEanim.gotoAndPlay(41);}

               

              if(homeHOMEanim.currentFrame >= 11 && homeHOMEanim.currentframe <=16){

              homeHOMEanim.gotoAndPlay(42);}

              }

            • 3. Re: Piece of code doesn't play for CLICK animation
              kglad Adobe Community Professional & MVP

              use the trace statement to debug your code.  start by confirming that ClickHome is called when you click myHomeButton.

              • 4. Re: Piece of code doesn't play for CLICK animation
                joep1240785 Level 1

                myHomeButton.addEventListener(MouseEvent.CLICK, ClickHome);

                function ClickHome(event: MouseEvent): void {

                  if (homeHOMEanim.currentFrame == 1 || homeHOMEanim.currentFrame == 2 || homeHOMEanim.currentFrame == 3) {

                  homeHOMEanim.gotoAndPlay(36);

                  }

                  if (homeHOMEanim.currentFrame == 4 || homeHOMEanim.currentFrame == 5 || homeHOMEanim.currentFrame == 6 || homeHOMEanim.currentFrame == 7) {

                  homeHOMEanim.gotoAndPlay(39);

                  }

                  if (homeHOMEanim.currentFrame == 8 || homeHOMEanim.currentFrame == 9 || homeHOMEanim.currentFrame == 10 || homeHOMEanim.currentFrame == 11) {

                  homeHOMEanim.gotoAndPlay(41);

                  }

                  if (homeHOMEanim.currentFrame == 12 || homeHOMEanim.currentFrame == 13 || homeHOMEanim.currentFrame == 14 || homeHOMEanim.currentFrame == 15) {

                  homeHOMEanim.gotoAndPlay(42);

                  }

                }

                For whatever reason - this worked, but the other one with the '&&' didn't.

                • 5. Re: Piece of code doesn't play for CLICK animation
                  kglad Adobe Community Professional & MVP

                  the logic in the two are different.