# This for array colllision function doesn't work with anything but first object in array [closed]

For some reason, this simple simple loop is totally broken. (characterSheet is my character Class, it's just a movieClip with some extra functionality) (hitBox, is basically a square movieclip)

Anyway: every time hitBox make contact with a characterSheet in a different order than they were created: Nothing happens. The program only seems to be listening to collisions that are made with o2[0]. As soon as another hitBox is created, it pushes the last one out of o2[0] and the last one becomes totally useless. What's super weird is that I can hit characterSheets in any order I like....

    public function collisions(o1:Array, o2:Array)
{
if((o1.lenght>=0)&&(o2.length>=0)){
for (var i = 0; i < o1.length; i++)
{
var ob1 = o1[i];
for (var f = 0; f < o1.length; f++)
{
var ob2 = o2[f];

if (ob1 is characterSheet)
{   if (ob2.hitTestObject(ob1))
{
var right:Boolean = true;
if (ob1.x < hitBox(ob2).origin.x)
right = false;
characterSheet(ob1).specialDamage(hitBox(ob2).damageType, hitBox(ob2).damage, right);
}}}}}}


Also it might be somewhat helpful to see the function for creating a new hitBox

    public function SpawnHitBox(targeted, following, atype, xoff, yoff, ... args)
{
var newHitBox = new hitBox(targeted, following, atype, xoff, yoff, args);

}


## closed as too localized by MichaelHouse♦, Josh♦, bummzack, Anko, Trevor PowellApr 13 '13 at 0:55

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. If this question can be reworded to fit the rules in the help center, please edit the question.

• Should it be for (var f = 0; f < o2.length; f++)... just skimmed the code, that seemed to stand out. If there is only one object in o1 array, then you will get a single collision only – Samaursa Apr 5 '12 at 2:18
• HAHA! Stupid mistake, wasted half the day trying to fix it, thanks...Edit:Didn't fix the problem. Though I did find a solution that works for some reason: I have just made it so that when hitBox's are done resizing-animating etc.. They fly 9000 pixels off screen and patiently wait to be collected until the badCollisionObjects.length>=10 when they are spliced. – Zee Bashew Apr 5 '12 at 2:34
• ;), in that case, I'll put that as the answer – Samaursa Apr 5 '12 at 2:36

I think it should be: for (var f = 0; f < o2.length; f++)... just skimmed the code, that seemed to stand out. If there is only one object in o1 array, then you will get a single collision only