# Error in code

**URL:** <https://forum.kirupa.com/t/error-in-code/306603>\
**Category:** flash\
**Created:** [March 18, 2010, 9:24am UTC](https://forum.kirupa.com/t/error-in-code/306603 "2010-03-18T09:24:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![RebeccaLessay](https://avatars.discourse-cdn.com/v4/letter/r/ee7513/32.png) [@RebeccaLessay](https://forum.kirupa.com/u/RebeccaLessay)\
**Post date:** [March 18, 2010, 9:24am UTC](https://forum.kirupa.com/t/error-in-code/306603/1 "2010-03-18T09:24:03Z")

</div>

Hey,

I’m currently working on a sliding puzzle game. I wrote a code where the block is only supposed to move if it’s current spot in array -1, +1, -5, +5 is null.  
If its not its should trace “end” But now I set the array so that every block around it isn’t null. And still when I click the block it moves AND traces “end”. There’s something I’m doing wrong but can’t seem to figure out what.

```auto
var wall:Number;
var conditionMet:Boolean = false;
var blockList:Array = new Array
	(wall,wall,wall,wall,wall,
	 	wall,
	 	null,mcBlock0,mcBlock1,
		wall,wall,
		wall,wall,wall,
		wall,wall,
		null,null,null,
	 wall,wall,wall,wall,wall,wall);

mcBlock0.addEventListener(MouseEvent.CLICK, movement);
mcBlock1.addEventListener(MouseEvent.CLICK, movement);

function movement(event:MouseEvent):void
{
	
	for(var blockNumber:uint = 0; blockNumber < blockList.length;blockNumber++)
	{
		if(blockNumber == 0 && blockList[blockNumber - 1] == null)
		{
			event.currentTarget.x -= 100;
			conditionMet = true;
		}
		else if(blockNumber == 0 && blockList[blockNumber + 1] == null)
		{
			event.currentTarget.x += 100;
			conditionMet = true;
		}
		else if(blockNumber == 0 && blockList[blockNumber - 5] == null)
		{
			event.currentTarget.y -= 100;
			conditionMet = true;
		}
		else if(blockNumber == 0 && blockList[blockNumber + 5] == null)
		{
			event.currentTarget.y += 100;
			conditionMet = true;
		}
		else if(blockNumber != 0 && blockList[blockNumber -1] != null)
		{
			conditionMet = false;
			trace ("end");
		}
		else if(blockNumber != 0 && blockList[blockNumber +1] != null)
		{
			conditionMet = false;
			trace ("end");
		}
		else if(blockNumber != 0 && blockList[blockNumber -5] != null)
		{
			conditionMet = false;
			trace ("end");
		}
		else (blockNumber != 0 && blockList[blockNumber +5] != null)
		{
			conditionMet = false;
			trace ("end");
		}
				
	}
	
} 

```
