# TypeError #1010 and undefined array indexes

**URL:** <https://forum.kirupa.com/t/typeerror-1010-and-undefined-array-indexes/245662>\
**Category:** flash\
**Created:** [December 2, 2007, 6:15pm UTC](https://forum.kirupa.com/t/typeerror-1010-and-undefined-array-indexes/245662 "2007-12-02T18:15:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Domox](https://avatars.discourse-cdn.com/v4/letter/d/35a633/32.png) [@Domox](https://forum.kirupa.com/u/Domox)\
**Post date:** [December 2, 2007, 6:15pm UTC](https://forum.kirupa.com/t/typeerror-1010-and-undefined-array-indexes/245662/1 "2007-12-02T18:15:52Z")

</div>

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:

```auto
TypeError: Error #1010: A term is undefined and has no properties.

```

```auto
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!
