10 Replies Latest reply: Jan 1, 2013 10:40 PM by cams_zalzos RSS

    Parameter hitTestObject must be non-null.

    cams_zalzos

      I am creating a game wherein there are 4 buttons. The 4 buttons are baskets with labels of solid, liquid, gas and fire. When the button is clicked, the basket that the catcher/character is holding will change depending on what the button is clicked. The changing of the basket  is okay now. I placed the changing of basket animation inside the character/catcher movieClip and what I do is that when I clicked the desired basket, I will call the gotoAndPlay function. Now, my problem is regarding my hitTestObject. I want the solid objects to be catching the solid objects only and so on. But whenever I clicked on the button, the basket will change but the catcher/character won't move because of this error. What should I do? >.<

       

      Here is my code in hitTestObject:

       

      public function moveObjects(e:Event) {

      for (var i: int = objects.length -1; i >= 0; i--) {

      objects[i].y += speed;

      addChild(objects[i]);

       

      if (objects[i].hitTestObject(catcher.mouth_mc_2)) {

            if (objects[i].typestr == "solid") {

            score += 5;

            soundfx_1.play();

            catcher.mouth_mc_2.gotoAndPlay(9);

            }

           else

           {

           score -= 5;

           soundfx_2.play();

           catcher.mouth_mc_2.gotoAndPlay(2);

           }

       

           if (score < 0) score = 0;

       

          ScoreDisplay.text = String(score);

          removeChild(objects[i]);

          objects.splice(i, 1);

          }

       

         else if (objects[i].hitTestObject(catcher.mouth_mc_3)) {

               if (objects[i].typestr == "liquid") {

               score += 5;

               soundfx_1.play();

               catcher.mouth_mc_3.gotoAndPlay(9);

               }

             else

              {

              score -= 5;

              soundfx_2.play();

              catcher.mouth_mc_3.gotoAndPlay(2);

              }

       

             if (score < 0) score = 0;

       

            ScoreDisplay.text = String(score);

            removeChild(objects[i]);

            objects.splice(i, 1);

            }

       

           else if (objects[i].hitTestObject(catcher.mouth_mc_4)) {

                  if (objects[i].typestr == "gas") {

                  score += 5;

                  soundfx_1.play();

                  catcher.mouth_mc_4.gotoAndPlay(9);

                  }

                  else

                  {

                  score -= 5;

                  soundfx_2.play();

                  catcher.mouth_mc_4.gotoAndPlay(2);

                  }

       

                  if (score < 0) score = 0;

       

                 ScoreDisplay.text = String(score);

                 removeChild(objects[i]);

                 objects.splice(i, 1);

                 }

       

                 else if (objects[i].hitTestObject(catcher.mouth_mc_5)) {

                  if (objects[i].typestr == "fire") {

                  score += 5;

                  soundfx_1.play();

                  catcher.mouth_mc_5.gotoAndPlay(9);

                  }

                  else

                  {

                  score -= 5;

                  soundfx_2.play();

                  catcher.mouth_mc_5.gotoAndPlay(2);

                  }

       

                  if (score < 0) score = 0;

       

                  ScoreDisplay.text = String(score);

                  removeChild(objects[i]);

                  objects.splice(i, 1);

                  }

       

          else if (objects[i].hitTestObject(boundary)) {

                  removeChild(objects[i]);

                  objects.splice(i, 1);

                  }

       

                  catcher.x = mouseX;

                  checkStageBorder();

                  }

      }