4 Replies Latest reply on Jul 20, 2007 11:43 PM by kglad

    hit detection

      I have a drag and drop game where there are multiple draggable items and multiple targets. The standard hitTest() method is quite cumbersome to use in this case where I have to do a hitTest for each target when a draggable item is dropped. I could always use a loop and have my targets instance names be the same and append a number to it but I was wondering:

      Is there a way to get the hitted instance returned to the draggable item when this one is released using a custom class because I'm quite sure Flash doesn't provide such a method?

      Something like:

      myItem.onRelease = function() {
      if (this.matchingCriteria == this.hitted.matchingCriteria) trace("Youppie");

      instead of:

      myItem.onRelease = function() {
      for (var i=0; i<nTargets; i++) {
      if (this.matchingCriteria == this["target"+i].matchingCriteria) trace("Youppie");

      While a for loop might be a solution, I would prefer something that doesn't rely on having standard names for the targets.

      One may suggest to store all the targets in an array but it can be quite time consuming when you have dozens of targets and they are not all available at the same time. I guess one could have an "available" property in each target but that's just getting out of hands.

      Thankx for any insights.