user2740392
user2740392

Reputation: 37

Error in Actionscript 3 - "TypeError: Error #1010: A term is undefined and has no properties."

I cannot for the life of me find any undefined term in this code. The compiler isn't returning a line, just an error that says, "TypeError: Error #1010: A term is undefined and has no properties. at Snakev1_fla::MainTimeline/update()"

Here's the code:

    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]);
    }

}

Upvotes: 0

Views: 4829

Answers (1)

TreeTree
TreeTree

Reputation: 3230

At least one of your variables are null. You can set a breakpoint at the start of the function and step line by line until it crashes, which should tell you the problem line, and problem variable.

You can also put

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

at the start of your function. The program will still crash but it will trace every variable, and at least one of them should return true.

Upvotes: 2

Related Questions