I am trying to access a child so I can do some hitTest with that child but I get this error, which you may have seen a million times, and enough times to understand what it means, unlike me (new to As3).
1119: Access of possibly undefined property ground through a reference with static type flash.display:Sprite.
Saything, here is some code.
I initiate everything in the main constructor and then add it to the stage
addChild(_scrollLayer);
//player
_scrollLayer.addChild(character);
//character.reset();
//character.x = 640;
character.y = 0;
//level
_scrollLayer.addChild(ground);
ground.x = 640;
ground.y = 680;
//greenGoblin
_scrollLayer.addChild(goblin1);
goblin1.x = 500;
goblin1.y = 0;
_scrollLayer.addChild(goblin2);
goblin2.x = 800;
goblin2.y = 0;
_scrollLayer.addChild(goblin3);
goblin3.x = 100;
goblin3.y = 0;
//red Goblin
_scrollLayer.addChild(redGoblin1);
redGoblin1.x = 1100;
redGoblin1.y = 400;
while (_scrollLayer.ground.hitTestPoint(getChildAt(c).x, getChildAt(c).y, true))
This is when I get the ERROR message that you have seen above.
I have tried doing this also
while (ground.hitTestPoint(getChildAt(c).x, getChildAt(c).y, true))
No error message, how ever the hitTest does not work, this is because everything is in a container.
Here is the full hit Test code
for (var c:int = 0; c < childrenOnStage; c++)
{
if (getChildAt(c).name == "player")
{
if (ground.hitTestPoint(getChildAt(c).x, getChildAt(c).y, true))
{
touchingGround = true;
while (ground.hitTestPoint(getChildAt(c).x, getChildAt(c).y, true))
{
OnGround(getChildAt(c)).incrementUp();
if (ground.hitTestPoint(getChildAt(c).x, getChildAt(c).y, true))
{
}
else
{
OnGround(getChildAt(c)).keepOnGround();
}
}
}
else
{
touchingGround = false;
//trace("not touch");
//character.gotoAndStop("jump");
}
}
//childrenOnStage is a variable. childrenOnStage = this.numChildren;
I do not understand why the hit test is not working. I would appreciate an answer, advice or tip please.
Thank you.