Parameter hitTestObject must be non-null.
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.y += speed;
addChild(objects);
if (objects.hitTestObject(catcher.mouth_mc_2)) {
if (objects.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);
objects.splice(i, 1);
}
else if (objects.hitTestObject(catcher.mouth_mc_3)) {
if (objects.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);
objects.splice(i, 1);
}
else if (objects.hitTestObject(catcher.mouth_mc_4)) {
if (objects.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);
objects.splice(i, 1);
}
else if (objects.hitTestObject(catcher.mouth_mc_5)) {
if (objects.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);
objects.splice(i, 1);
}
else if (objects.hitTestObject(boundary)) {
removeChild(objects);
objects.splice(i, 1);
}
catcher.x = mouseX;
checkStageBorder();
}
}
