1 Reply Latest reply: Apr 12, 2013 11:12 AM by Ned Murphy RSS

    Problem with hitTest and gotoAndStop()

    EnigmaWarrior

      I am working on a small game and I want to write a code so when my human character hits a meteor you go to frame 4 in the timeline.

       

      I have written this code in the human actions:

       

      ....

      if ( this.hitTest(_root.meteor1) ) {

       

      gotoAndStop(4);

       

      }

       

      When trying it shows no errors but it does not work.

       

      Any help is appreciated here.

       

      Thanks :-)

        • 1. Re: Problem with hitTest and gotoAndStop()
          Ned Murphy CommunityMVP

          You need to constantly be checking for the hit.  If you do not have that code constantly cycling then you need to make it so.

           

          YOu can try using an enterFrame function for it...

           

          this.onEnterFrame = function(){

              if ( this.hitTest(_root.meteor1) ) {

                  delete this.onEnterFrame;

                  gotoAndStop(4);

              }

          }