2 Replies Latest reply on Sep 28, 2009 6:36 AM by Jokken123

    Event propagation and inheritance




      I have a button inheriting from another. In the ancester I have a CLICK event handler registered.I have another CLICK event handler in the descendent button. In the descendent I want to handle the CLICK event combined with the CTRL key. Without the CTRL key I want the the ancester event handler to do it's work. I tried different combinations of StopPropagation(), StopImmediatePropagation priorities, etc...with no satisfactory result. Sometimes both event handlers are triggered, sometimes only the event handler for the descendent is triggered. What would be the way to do this. Thanks in advance.

        • 1. Re: Event propagation and inheritance
          _Natasha_ Level 4



          frankly spaeking I can't understand your problem.


          You have a button and two listeners for CLICK event. You can't say what handler will be the first.

          One handler should check CTRL key and other don't.


          If handlers is in one component you should use stopImmediatePropagation() to stop processing, but you don't know the order, so sometimes it work, sometimes second handler is called first and it's not affected as you want.

          • 2. Re: Event propagation and inheritance
            Jokken123 Level 1

            Thanks Natasha,


            I solved my problem by overriding the click event handler in the descendent like:




            override protected function clickHandler(event:MouseEvent):void {

                 if (event.ctrlKey) {

                      ...do the stuff in case of CTRL-key held

                 } else {

                      // Do ancestor work for normal click         





            So...no need for stopping propagation of the event