2 Replies Latest reply on Jul 30, 2009 9:15 AM by nikos101

    I want to have 2 listeners for the same event

    nikos101 Level 2

      I want to have 2 listeners for the same event but the latter (onKeyPress) is not being called upon KeyboardEvent.KEY_DOWN


                       this.addEventListener(KeyboardEvent.KEY_DOWN,HandleActivity);
                       this.addEventListener(KeyboardEvent.KEY_DOWN,onKeyPress);

       

      Anything I am missing?

        • 1. Re: I want to have 2 listeners for the same event
          Gregory Lafrance Level 6

          In this code both listeners are called:

           

          If this post answers your question or helps, please mark it as such.

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
            creationComplete="init();" width="100%" height="100%">
            <mx:Script>
              <![CDATA[
                import mx.controls.Alert;
               
                private function init():void{
                  btn.addEventListener(KeyboardEvent.KEY_DOWN,HandleActivity);
                  btn.addEventListener(KeyboardEvent.KEY_DOWN,onKeyPress);
                }
               
                private function HandleActivity(evt:KeyboardEvent):void{
                  mx.controls.Alert.show("In HandleActivity().");
                }

                private function onKeyPress(evt:KeyboardEvent):void{
                  mx.controls.Alert.show("In onKeyPress().");
                }
              ]]>
            </mx:Script>
            <mx:VBox id="vb" width="100%" height="100%" backgroundColor="0xFFFFFF">
              <mx:Button id="btn" label="Click Me"/>
            </mx:VBox>
          </mx:Application>