hitTestObject not working properly within a for loop

46 Views Asked by At

I'm building a game where the hero is build with a MovieClip that has nested Movieclips. The nested MovieClips are the moves of the hero which are in different frames. Additionally, there are some MovieClips that are two levels nested.

Now here is the code of what I'm doing:

    public function movesCollisions(event:Event):void{

        for (var ea:int = 0; ea < enemies.length; ea++){
              //parent  .child     .sibling     
             if(sketch.slidepunch.sketchfist.hitTestObject(enemies[ea])){

                enemies[ea].animstate = "defeated";
            //Here this first collision works fine but the next 
            //collsion below does not, I have no Idea why.  

     }else if(sketch.archforward.rhandHit.hitTestObject(enemies[ea])){

                enemies[ea].animstate = "defeated";

             }

                }
            }

The problem that I'm having is that the hitTestObject does not work when I have the else if conditional. The first one works if I comment out the else statement. How can I fix this issue since I have many more moves that I need to check for collision.

They only way that I have manage to get the moves collision to work has been by creating a different Event.ENTER_FRAME, function for each but it has a big effect on performance.

any guidance is greatly appreciated.

0

There are 0 best solutions below