5 Replies Latest reply on May 30, 2011 4:24 AM by pauland

    ROLL_OUT is fired with ROLL_OVER

    Madhav Subedi Level 4

      my code is

                  private function init():void
                  {
                      txtg.addEventListener(MouseEvent.ROLL_OVER, manageMouseOver);
                  }
                  
                  private function manageMouseOver(e:MouseEvent):void
                  {
                   e.currentTarget.removeEventListener(MouseEvent.ROLL_OVER, manageMouseOver);
                  e.currentTarget.addEventListener(MouseEvent.ROLL_OUT, manageMouseOut);
                  Alert.show('over');
                  }
                  
                  private function manageMouseOut(e:MouseEvent):void
                  {
                   e.currentTarget.removeEventListener(MouseEvent.ROLL_OUT, manageMouseOut);
                  e.currentTarget.addEventListener(MouseEvent.ROLL_OVER, manageMouseOver);
                  Alert.show('out');     
                  }
      

       

      where init() being called on creationComplete of application

       

      but, when i move mouse over the textbox - txtg - i get two alerts - first 'over', then 'out' ( i have not moved mouse out of the text yet )..

       

      bit confused.. can anyone help?

        • 1. Re: ROLL_OUT is fired with ROLL_OVER
          markerline Level 4

          I'm assuming your Alert works similar to a trace function in ActionScript (Flash ActionScript 3.0).

           

          subedimadhav wrote:

           

          my code is

           

                      private function init():void
                      {
                          txtg.addEventListener(MouseEvent.ROLL_OVER, manageMouseOver);
                      }
                      
                      private function manageMouseOver(e:MouseEvent):void
                      {
                       e.currentTarget.removeEventListener(MouseEvent.ROLL_OVER, manageMouseOver);
                      e.currentTarget.addEventListener(MouseEvent.ROLL_OUT, manageMouseOut);
                      Alert.show('over');
                      }
                      
                      private function manageMouseOut(e:MouseEvent):void
                      {
                       e.currentTarget.removeEventListener(MouseEvent.ROLL_OUT, manageMouseOut);
                      e.currentTarget.addEventListener(MouseEvent.ROLL_OVER, manageMouseOver);
                      Alert.show('out');     
                      }
          

           

           

          where init() being called on creationComplete of application

           

          but, when i move mouse over the textbox - txtg - i get two alerts - first 'over', then 'out' ( i have not moved mouse out of the text yet )..

           

          bit confused.. can anyone help?

          In your code you have the Alert firing both times because the function actually is being called both times to add and remove event listeners for Roll_Out and Roll_Over.  The functions are both calling Alerts so that is to say that the functions are actually working.

           

          My guess is that your Alert is simply giving you feedback but the code is what you should be worried about and whether it does what you state it to do.  Do you wish to addEventListener for ManageMouseOver for a MouseEvent.ROLL_OUT?  And vice versa for the manageMouseOut event?

          • 2. Re: ROLL_OUT is fired with ROLL_OVER
            markerline Level 4

            You may want to add an if statement if you want your Alerts to have a condition that the

            RollOut and RollOver events have been called/executed/fired (whatever expression you want to use to

            say that they have been initialized)

            • 3. Re: ROLL_OUT is fired with ROLL_OVER
              pauland Level 4

              The Alert box is popping up over the text box? ..in which case the mouse will no longer be over the control.

              • 4. Re: ROLL_OUT is fired with ROLL_OVER
                Madhav Subedi Level 4

                @Pauland:

                yes, and i think both the events are firing at once... first roll_over, and roll_out immediately...

                • 5. Re: ROLL_OUT is fired with ROLL_OVER
                  pauland Level 4

                  The Alert popup is triggering a MOUSE_OUT. If you use trace instead you will see that the events fire as you would expect.