1 Reply Latest reply on Jun 5, 2007 2:47 PM by kglad

    using hitTest inside a class

    tag_digital
      Could someone please point me in the right direction here?

      I have a class that I want to use to instantiate 'hit-able' movieclips on the screen. I want to create them on the fly. I want to have these 'widgets' watch for a hit of another object that is 'fired' from another object. I can't figure out a way to have the 'widget' watch for the fired object? I'd like to pass the hit object at the time I create the 'widget'. I have tried a few different ways to pass the 'hitObject' (below) but I can't seem to figure out a way to do that. the code below is an example of what I want to do but obviously the 'hitObject' in the function watchForHit is not passed. Is there a way I can pass it at the time I create the widget?
      QUESTION #2...What if you don't know the name of the object that is going to hit? Is there a way to test what object has hit my listening object if I don't know what object I'm listening for That way I could just listen to see if anything has hit. THANKS!

      public class widget extends MovieClip{

      public var counter:int;

      public function widget(){
      counter = 0;
      This.addEventListener(Event.ENTER_FRAME, watchForHit);
      }

      private watchForHit(event:Event):void {
      if(this.hitTest(hitObject)) this.counter++;
      }
      }