Actionscript 3中的错误 - “TypeError:错误#1010:术语未定义且没有属性。”

时间:2014-03-17 15:57:37

标签: actionscript-3

我不能为我的生活在这段代码中找到任何未定义的术语。编译器没有返回一行,只是一个错误,上面写着“TypeError:错误#1010:一个术语未定义且没有属性。     在Snakev1_fla :: MainTimeline / update()“

以下是代码:

    function update(e:Event):void
{
    if (keys[Keyboard.RIGHT])
    {
        directions["right"] = true;
    }

    if (keys[Keyboard.LEFT])
    {
        directions["left"] = true;
    }
    if (keys[Keyboard.UP])
    {
        directions["up"] = true;
    }
    if (keys[Keyboard.DOWN])
    {
        directions["down"] = true;
    }
    var i:int = segments.length - 1;
    while (i > 0)
    {
        segments[i].y = locations[locations.length - 6][1];
        segments[i].x = locations[locations.length - 6][0];
        i--;
    }
    if (directions["right"])
    {
        head.x +=  5;
    }
    if (directions["left"])
    {
        head.x -=  5;
    }
    if (directions["up"])
    {
        head.y -=  5;
    }
    if (directions["down"])
    {
        head.y +=  5;
    }
    directions["up"] = false;
    directions["down"] = false;
    directions["left"] = false;
    directions["right"] = false;

    locations[locations.length][0] = head.x;
    locations[locations.length][1] = head.y;

    trace(locations);

    if (head.x < food.x + food.width / 2 + head.width / 2 && head.x > food.x - food.width / 2 - head.width / 2 && head.y > food.y - food.height / 2 - head.height / 2 && head.y < food.y + food.height / 2 + head.height / 2)
    {
        food.x = Math.random() * 490;
        food.y = Math.random() * 490;

        var body:part = new part();

        body.x = locations[locations.length - 6][0];
        body.y = locations[locations.length - 6][1];
        body.width = head.width;
        body.height = head.height;
        segments[segments.length] = body;
        addChild(segments[segments.length-1]);
    }

}

1 个答案:

答案 0 :(得分:2)

至少有一个变量为null。您可以在函数的开头设置一个断点,逐行逐步,直到它崩溃,这应该告诉您问题行和问题变量。

你也可以把

trace (keys == null);
trace (directions == null);
//and so on for every variable

在你的功能开始时。程序仍然会崩溃,但它会跟踪每个变量,并且至少其中一个变量应该返回true。