3 Replies Latest reply on Nov 25, 2011 9:39 AM by kglad

    Hittest Not Working

    olafgarten212

      This is my code it is not working

       

      on (keyPress "<Left>") {
           currentX = this._x;
           this._x = currentX - 5;
           
      if(this.hitTest(_root.leftbord)) { this._y++; }  
      
      
      
      }
      on (keyPress "<Right>") {
           currentX = this._x;
           this._x = currentX + 5;
           if(this.hitTest(_root.rightbord)) { this._y--; }
      
      }
      
      
      
        • 1. Re: Hittest Not Working
          Ned Murphy Adobe Community Professional & MVP

          If I try the code it does what the code says to do, so what aspect of it is not working for you?  Have you assigned the instance names you use to the objects you are hitTest-ing? 

          1 person found this helpful
          • 2. Re: Hittest Not Working
            olafgarten212 Level 1

            when i crash into the wall i walk right past it and i have set the instance name

            • 3. Re: Hittest Not Working
              kglad Adobe Community Professional & MVP

              that's what you've coded:  when you're using the left key and hit "this", you move to the left and when using the right key, you move to the right.

               

              if you want to rebound use:

               

              on (keyPress "<Left>") {
                   currentX = this._x;
                   this._x = currentX + 5;
                  
              if(this.hitTest(_root.leftbord)) { this._y++; } 



              }
              on (keyPress "<Right>") {
                   currentX = this._x;
                   this._x = currentX - 5;
                   if(this.hitTest(_root.rightbord)) { this._y--; }

              }

              1 person found this helpful