To compare the cells and have them move towards each other if they are below 200px apart (for example):
var maxDistance: Number = 200;
var minDistance: Number = 20;
var len:int = listOfCells.length;
for (var j:int =0; j < len; j++)
{
var cell: Cell = listOfCells[j];
for(var k:int = 0; k < len; k++)
{
var cellToCompare = listOfCells[k];
if(cellToCompare != cell) {
var dx: Number = cellToCompare.x - cell.x;
var dy: Number = cellToCompare.y - cell.y;
var distance : Number = Math.sqrt(dx * dx + dy * dy);
if(distance < maxDistance && distance > minDistance) {
cell.x = cell.x + dx * 0.1;
cell.y = cell.y + dy * 0.1;
}
}
}
}
Also to be sure the array only contains Cell instances, use the 'is' operator:
var listOfCells:Array = new Array();
for (var i:int =0; i < (root as MovieClip).numChildren; i++)
{
var child: DisplayObject = (root as MovieClip).getChildAt(i);
if(child is Cell) {
listOfCells.push(child);
}
}