# Problem with 2D array and Null values

**URL:** <https://forum.kirupa.com/t/problem-with-2d-array-and-null-values/274086>\
**Category:** flash\
**Created:** [October 24, 2008, 5:01pm UTC](https://forum.kirupa.com/t/problem-with-2d-array-and-null-values/274086 "2008-10-24T17:01:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SticksStones](https://avatars.discourse-cdn.com/v4/letter/s/c68b51/32.png) [@SticksStones](https://forum.kirupa.com/u/SticksStones)\
**Post date:** [October 24, 2008, 5:01pm UTC](https://forum.kirupa.com/t/problem-with-2d-array-and-null-values/274086/1 "2008-10-24T17:01:26Z")

</div>

I’m sure this is a really simple question for anyone who’s come across it before.  
I have a grid of objects. I’m comparing properties of objects above, below, left and right of an object in the grid when clicked.

This is fine until I click on an object on one of the sides of the grid, then it’s returning null - like you’d expect.

I thought i’d solved the problem like this…

right = GlobalVars.allBlocks[row][col + 1];  
if (right == null) { right = GlobalVars.empty; }  
left = GlobalVars.allBlocks[row][col - 1];  
if (left == null) { left = GlobalVars.empty; }  
above = GlobalVars.allBlocks[row - 1][col];  
if (above == null) { above = GlobalVars.empty; }  
below = GlobalVars.allBlocks[row + 1][col];  
if (below == null) { below = GlobalVars.empty; }

However this only works with the “left” and “right” MovieClip references, but the “top” and “bottom” throw a TypeError: Error #1010: A term is undefined and has no properties. - if i try to catch the error it throws a TypeError: Error #1009!

Why would the left and right work fine, but not the top and bottom?!

Any ideas?

Andy
