Hey,
im running a quick program that checks if some objects are touching each other. What im trying to do is push the groups of objects that are touching each other into one of an array in a 2d array. and then continue through all the other objects that are touching and add them to their own array in the 2d array.
My current code is posted below:
and the image is embedded as well.
var i:int = 0;
var q:int = 0;
var objs:Array = new Array(); // holds all objects on the screen to be checked for grouping
var groups:Array = new Array(); // this is the array that will be 2d (see loop)
objs.push(a); //push objects into array for testing
objs.push(b);
objs.push(c);
objs.push(d);
objs.push(e);
objs.push(f);
objs.push(g);
for(i=0; i<objs.length; i++){
//search group for objects that are already in the group (It's not here, this is a note for me though)
// continue with code below
if(objs* is MovieClip){ // I will have different objects that can only be checked to see if they are touching objects of the same type like 'objs* is RedBox'
groups.push(new Array());
groups[groups.length-1].push(objs*);
for(q=i+1; q<objs.length; q++){
if(objs*.hitTestObject(objs[q])){
groups[groups.length-1].push(objs[q]);
}
}
}
}
for(i=0; i<groups.length; i++){
//trace(groups*);
var txt:String = "";
for(q=0; q<groups*.length; q++){
txt += groups*[q].name;
}
trace(txt);
}
/* outputs:
abc
bg
c
d
ef
f
g
*/

Thanks,
Thomas Francis