2 Replies Latest reply on Oct 3, 2010 12:45 PM by bignuttjob

    How to remove a click event

    bignuttjob Level 1



      I have created an image id="myImage" in flex with a click event, i.e.  click="myFunction(e)"

      In myFunction I want to remove or disable the click event in the event handler (ActionScript). I have tried

          myImage.removeEventListener('click', myFunction, false) ;

          myImage.removeEventListener( MouseEvent.CLICK, myFunction, true);
          myImage.removeEventListener( MouseEvent.CLICK, myFunction, false);

      myImage.click = NULL; isn't allowed...;-(


      Can you help?



        • 1. Re: How to remove a click event
          pauland Level 4

          I think the problem may be that the mxml click notation makes a handler on your behalf  and you supply the body (think anonymous function). So you supply the body of the click handler which calls your handler, but your handler is not actually the name of the click handler itself.


          If you want to be able to remove the function, explicitly create a handler using addEventListener rather than the mxml convenience mechanism, or alternatively create a flag for the handler to check to see if it should do anything or not.



          • 2. Re: How to remove a click event
            bignuttjob Level 1

            Thanks Paul!

            That worked!