1 Reply Latest reply on Sep 14, 2010 8:32 AM by rtalton

    How to prevent a rollOut while dragging

    SiHoop Level 1

      I'm building an interface in which I have to drag a button. If I drag the button too quickly, the mouse rolls out of the button for a moment. The idea is illustrated in the following code-- drag the mouse down rapidly and you'll trigger a ROLL_OUT event if you do it fast enough. The event triggers a trace statement.

       

      What I want to do is make sure that the mouse NEVER leaves the button as it is being dragged-- can this be done and if so how?

       

      Thank you!

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"   creationComplete="init()">
          <mx:Script>
              <![CDATA[
      import mx.controls.Button;
      private var button:Button;
      private var dragRectangle:Rectangle;
      private function init():void{
              dragRectangle= new Rectangle(0, 0, 0, 500 )   
              button=new Button;
              button.addEventListener(MouseEvent.MOUSE_DOWN, dragButton)
              button.width=100;
              button.height=30;
              mainContainer.addChild(button);
      }
      public function dragButton(e:MouseEvent):void {       
          //e.currentTarget.addEventListener(MouseEvent.MOUSE_OUT,draggedOut)
          e.currentTarget.addEventListener(MouseEvent.ROLL_OUT,draggedOut)
          e.currentTarget.startDrag(false, dragRectangle);
          e.currentTarget.addEventListener(MouseEvent.MOUSE_UP, stopButton);
      }
      public function stopButton(e:MouseEvent):void{
          e.currentTarget.stopDrag()
      }
      private function draggedOut(e:MouseEvent):void{
          trace("Dragged out at y="+e.currentTarget.y)
      }
              ]]>
          </mx:Script>
          <mx:Canvas   id="mainContainer" x="400" y="25"   />
      </mx:Application>