Hi me again
Got the script working now but not as I want it to.
The trouble lies in the for-loop. What I want it to do is: perform 1 if and then end the loop and sent the new data to erhm…something that remembers it
So the next time you click a block the loop starts with the new data etc etc.
var blockList = new Array();
for(var i:int = 0; i < 25; i++)
{
var xAs:int = i % 5;
var yAs:int = i / 5;
var block:MovieClip;
if(xAs == 0 || yAs == 0 || xAs == 4 || yAs == 4)
{
block = new mcWall();
}
else if(xAs != 1 || yAs != 1)
{
block = new mcBlock();
block.addEventListener(MouseEvent.CLICK, movement);
}
else if(xAs == 1 && yAs == 1)
{
block = new mcEmpty();
}
block.x = xAs * 100;
block.y = yAs * 100;
addChild(block);
blockList* = block;
}
function movement(event:MouseEvent)
{
trace(event.target);
var clickedIndex:int = 0;
// zoek de juiste index waarde
for(var i:int = 0; i < blockList.length; i++)
{
if(blockList* == event.target)
{
clickedIndex = i;
}
}
// zoek de juiste index waarde van mcEmpty
for(var empty:int = 0; empty < blockList.length; empty++)
{
if(blockList[empty] == mcEmpty)
{
clickedIndex = empty;
}
}
// controleer om clickedIndex heen
if(blockList[clickedIndex -1] is mcEmpty)
{
event.currentTarget.x -= 100;
blockList.splice(clickedIndex -1);
blockList.splice(empty +1);
}
else if(blockList[clickedIndex +1] is mcEmpty)
{
event.currentTarget.x += 100;
//blockList.splice(clickedIndex +1);
// blockList.splice(empty -1)
}
else if(blockList[clickedIndex -5] is mcEmpty)
{
event.currentTarget.y -= 100;
//blockList.splice(clickedIndex -5);
// blockList.splice(empty +5)
}
else if(blockList[clickedIndex +5] is mcEmpty)
{
event.currentTarget.y += 100;
//blockList.splice(clickedIndex +5);
// blockList.splice(empty -5)
}
else if(blockList[clickedIndex +5]!= mcEmpty)
{
trace ("not possible");
}
else if(blockList[clickedIndex -5]!= mcEmpty)
{
trace ("not possible");
}
else if(blockList[clickedIndex +1]!= mcEmpty)
{
trace ("not possible");
}
else(blockList[clickedIndex -1]!= mcEmpty)
{
trace ("not possible");
}
trace(clickedIndex);
}