I'm writing a small simulation that's dealing with a large number of small MCs that are dynamically created.

I also need to run a hitTest that checks whether any clip is in contact with any other clip.

code:
function Hitdetect() {
for(i=0; i<=100; i++) {
if(this.hitdetectMC.hitTest(_root["character"+i])) {
proximity ++;
}
}
}



proximity is a variable inside each instance of the character MC.

The problem I have is that I need to create another function, Spawn, that creates another instance of the original character MC. The problem is, I don't know the best way to assign a name and depth to the newly created MC considering that some of the MCs will be deleted based on their own code.

Can someone suggest a way of storing the identity of the created movie clips?

I considered using an array to store the IDs of the instances, but everytime a new clip is created, the array will end up getting bigger and bigger, and the scanning of that array will end up slowing the whole processing down.