1 Reply Latest reply on Jul 27, 2010 2:25 PM by saisri2k2

    Event Listener launching the wrong function

    imsammyd

      Good day all.  I am stumped on this one.  Using flex 4 with flash builder 4.  I have a class where I extend the mx.mx.controls.Image.  I want to add a click handler to the class.  In the constructor of my Image class, I pass a function as an argument named click and then set is as such:

       

      public function MovingImage(source:String, xFrom:int, yFrom:int, xTo:int, yTo:int, easingFunction:Function, duration:int, click:Function, tt:String):void
              {
                  super();
                  this.source = source;
                  this.xFrom = xFrom;
                  this.yFrom = yFrom;
                  this.xTo = xTo;
                  this.yTo = yTo;
                  this.easingFunction = easingFunction;
                  this.duration = duration;
                  this.addEventListener(MouseEvent.CLICK, click);
                  this.toolTip = tt;
      
              }
      
      

       

      Initially it works great.  You click one of the MovingImages and it calls the specific function that I pass in.  The problem is then all subsequent clicks to different MovingObjects call the same function as the first one you clicked.  Let me reiterate.  The first MovingImage that is clicked has it's click function used for all other MovingImages.

       

      Am I adding the handler correctly?  Is there a better way to create my own image class and have special click handlers?

       

      Thanks in Advance.