I am working on converting a class from AS2 to AS3. Basically pos is created with MovieClips at different indexs (hardly ever starting at [0][0] because these indexs are made based on the clips location on a screen grid) and when it starts checking for neighbors sometimes the index it checks is undefined. Is there a way to check if that index is undefined and then proceed to the next without throwing:
TypeError: Error #1010: A term is undefined and has no properties.
public function getNeighbours(p_mc:MovieClip):Array {
var a:Number = Math.ceil(p_mc.x/gridSize);
var b:Number = Math.ceil(p_mc.y/gridSize);
var p:Array = pos;
var r:Array = p[a]**;
if (p[a-1][b-1]) { r = r.concat(p[a-1][b-1]); }
if (p[a][b-1]) { r = r.concat(p[a][b-1]); }
if (p[a+1][b-1]) { r = r.concat(p[a+1][b-1]); }
if (p[a-1]**) { r = r.concat(p[a-1]**); }
if (p[a+1]**) { r = r.concat(p[a+1]**); }
if (p[a-1][b+1]) { r = r.concat(p[a-1][b+1]); }
if (p[a][b+1]) { r = r.concat(p[a][b+1]); }
if (p[a+1][b+1]) { r = r.concat(p[a+1][b+1]); }
return r;
}
Thanks!