我想訪問一個孩子,所以我可以做一些hitTest與那個孩子,但我得到這個錯誤,你可能已經看到了一百萬次,並有足夠的時間來理解它的含義,不像我(As3的新手)。我不能訪問已添加到另一個孩子(它的父母)的孩子
1119: Access of possibly undefined property ground through a reference with static type flash.display:Sprite.
這是一些代碼。
我開始在主構造函數的一切,然後將其添加到舞臺
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))
這是當我得到您上面所看到的錯誤消息。
我試圖這樣做也
while (ground.hitTestPoint(getChildAt(c).x, getChildAt(c).y, true))
沒有錯誤消息,怎麼過了則hitTest是不行的,這是因爲一切都在一個容器中。
以下是完整的命中測試代碼
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;
我不明白爲什麼命中測試是行不通的。我會很感激的答覆,建議或提示請。
謝謝。
_scrollLayer是儘管順便說一句。 – Moynul