5 Replies Latest reply on Apr 1, 2007 8:31 AM by kglad

    hitTest inside array

    ottimoto Level 1
      Hi forum,

      I have a class called Ghost as an actionscript file. In my flash file I created an array and populate the array using push. On enterFrame I get my ghost instances to move calling a function inside the class - and that works. Now to do a hitTest between the moving ghosts is the hard bit. I obviously try to avoid that the ghost hits himself, but I think I 'm not referencing correctly to the instances in the array?
      Here is the part of the code:

      // Create array to hold movie clips ghosts.
      var ghostArray:Array = new Array();
      //
      // Loop to push 5 ghosts into array and display.
      for (var i:Number = 0; i <= 4; i++) {
      ghostArray.push(new Ghost())
      }

      // Constantly move the ghosts.
      this.onEnterFrame = function() {
      // Loop to get all elemenst in array.
      for (var j:Number = 0; j < _root.ghostArray.length; j++) {
      // Call function to move the objects.
      ghostArray[j].move();
      }
      for(i:Number = 0; i < _root.ghostArray.length; i++) {
      //
      if (this != _root.ghostArray && this.hitTest(_root.ghostArray)) {
      trace("collision between ghost");
      }
      }
      }

      Can anybody help? Very much appreciated.

      otti