3 Replies Latest reply on Aug 10, 2010 5:21 AM by Ned Murphy

    Checking entire array for collision? How? AS 2.0

    erikvasconcelosjansson

      Hi!

       

      I am doing a flash game with Actionscript 2.0 and have encountered a problem.

       

      I have this statement _root.bulletArray = [] that is storing all my movieclips that have been created with attachMovieClip. I was able to store all bullets in the array because when I say for it to trace the array I get the following:

      _level0.bulletCopy39
      _level0.bulletCopy39,_level0.bulletCopy43
      _level0.bulletCopy39,_level0.bulletCopy43,_level0.bulletCopy47
      _level0.bulletCopy39,_level0.bulletCopy43,_level0.bulletCopy47,_level0.bulletCopy51
      _level0.bulletCopy39,_level0.bulletCopy43,_level0.bulletCopy47,_level0.bulletCopy51,_level 0.bulletCopy55
      _level0.bulletCopy39,_level0.bulletCopy43,_level0.bulletCopy47,_level0.bulletCopy51,_level 0.bulletCopy55,_level0.bulletCopy59
      _level0.bulletCopy39,_level0.bulletCopy43,_level0.bulletCopy47,_level0.bulletCopy51,_level 0.bulletCopy55,_level0.bulletCopy59,_level0.bulletCopy63

       

      and etc...

       

      But how do I detect collision with ALL the bullets?

       

      I have a movieclip that has the instance name: enemy

      I have written the following:

       

      if(_root.bulletArray.hitTest(_root.enemy))

      {

      trace("hit")

      }

       

      It dosent work, notihing is traced in the command thing.

       

      But if I do the follwing:

       

      if(_root.bulletArray[1].hitTest(_root.enemy))

      {

      trace("hit")

      }

       

      then it will detect the collision, but only of that bullet, not of the entire array of bullets.

       

       

       

      Any help is highly appreciated! =D

       

       

      ----NOTE-----

      I have also tried the followign without sucess:

       

      if(_root.bulletArray[1,2,3,4,5,6,7,8,9,10].hitTest(_root.enemy))

      {

      trace("hit")

      }