Actionscript 3 Actionscript 3中出现错误-“;TypeError:Error#1010:术语未定义且没有属性;

Actionscript 3 Actionscript 3中出现错误-“;TypeError:Error#1010:术语未定义且没有属性;,actionscript-3,Actionscript 3,我在这段代码中找不到任何未定义的术语。编译器没有返回一行,只是返回一个错误:“TypeError:error#1010:a term未定义且没有属性。 在佛罗里达州的Snakev1_::MainTimeline/update() 代码如下: function update(e:Event):void { if (keys[Keyboard.RIGHT]) { directions["right"] = true; } if (keys[K

我在这段代码中找不到任何未定义的术语。编译器没有返回一行,只是返回一个错误:“TypeError:error#1010:a term未定义且没有属性。 在佛罗里达州的Snakev1_::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]);
    }

}
功能更新(e:事件):无效
{
if(键[键盘右])
{
方向[“正确”]=正确;
}
if(键[键盘左])
{
方向[“左”]=真;
}
if(键[Keyboard.UP])
{
方向[“向上”]=正确;
}
如果(键[键盘下])
{
方向[“向下”]=真;
}
变量i:int=segments.length-1;
而(i>0)
{
段[i].y=位置[locations.length-6][1];
段[i].x=位置[locations.length-6][0];
我--;
}
如果(方向[“右”])
{
头部x+=5;
}
如果(方向[“左”])
{
头部x-=5;
}
如果(方向[“向上”])
{
水头y-=5;
}
如果(方向[“向下”])
{
水头y+=5;
}
方向[“向上”]=错误;
方向[“向下”]=错误;
方向[“左”]=假;
方向[“正确”]=错误;
位置[locations.length][0]=头.x;
位置[位置.长度][1]=头部y;
跟踪(位置);
如果(head.xfood.x-food.width/2-head.width/2&&head.y>food.y-food.height/2-head.height/2&&head.y
至少有一个变量为空。您可以在函数的开头设置一个断点,并逐行执行,直到它崩溃,这将告诉您问题行和问题变量

你也可以把

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

在您的功能开始时。程序仍将崩溃,但它将跟踪每个变量,其中至少有一个应返回true。

非常好,谢谢。我对actionscript完全陌生,不知道调试模式。结果是位置列表出现了问题——添加一个新的列表元素的工作方式与我在PythonI中习惯的不同,我没有捕获这两行代码。不能使用数组以这种方式推送到列表。但是,如果使用向量,则可以按此方式。它几乎与数组相同,只是它是严格类型化的<代码>变量水果:向量新载体。()。