Hey party people,
I’m working on a project where I have an array of coordinate points (4 of them) and a menu system that, when clicked, rearranges the boxes so that they all move around. The problem is that the values I pull out of the array are not always unique so some of the items end up not moving (or sometimes it ends up moving two to the same spot because the last one didn’t move and one of them moved to a spot that is already occupied).
Here is the code I was using which for the most part works, except as mentioned, sometimes the check for the last one in the loop sees that the conditional is not equal so it doesn’t do anything because there is no other values to loop through and it just leaves it in that spot. i’m not sure how to fix this so any help would be greatly appreciated.
private function checkCoordinates($item:MenuItem, $coords:Array):Void
{
var numItems:Number = $coords.length;
for (var i:Number = 0; i < numItems; i++)
{
if (($item._x != $coords*.x) && ($item._y != $coords*.y))
{
var ret:Array = $coords.splice(i, 1);
var pt:Point = ret[0];
$item.moveTo(pt, 0);
break;
}
}
}
thanks to anyone who attempts to help, it’s greatly appreciated.