title: Error in Actionscript 3 - "TypeError: Error #1010: A term is undefined and has no properties."
body: <p>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()"</p>
  
  <p>Here's the code:</p>
  
  <pre><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 &gt; 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 &lt; food.x + food.width / 2 + head.width / 2 &amp;&amp; head.x &gt; food.x - food.width / 2 - head.width / 2 &amp;&amp; head.y &gt; food.y - food.height / 2 - head.height / 2 &amp;&amp; head.y &lt; 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]);
      }
  
  }
  </code></pre>