2 Replies Latest reply on May 24, 2010 8:33 AM by David_F57

    drag along x axis only

    dmodie Level 1

      I'm starting with this example for drag and drop (first one on page):

       

      http://livedocs.adobe.com/flex/3/html/help.html?content=dragdrop_7.html

       

      I would like to restrict the dragging to only the x direction.  Assume I want to edit the following function, but not sure what do to:

       

                  private function mouseMoveHandler(event:MouseEvent):void 
                  {               
                      var dragInitiator:Image=Image(event.currentTarget);
                      var ds:DragSource = new DragSource();
                      ds.addData(dragInitiator, "img");              

                      DragManager.doDrag(dragInitiator, ds, event);
                  }

      thanks
        • 1. Re: drag along x axis only
          prksingh Adobe Employee

          If you want to change where the image gets dropped, that can be easily done by changing the dragDropHandler method:

           

          private function dragDropHandler(event:DragEvent):void {
                          Image(event.dragInitiator).x =
                              Canvas(event.currentTarget).mouseX;
                          Image(event.dragInitiator).y = 15;
                      }

           

          This, will not restrict the movement of the Drag proxy though

          • 2. Re: drag along x axis only
            David_F57 Level 5

            hi,

             

            http://gumbo.flashhub.net/dragme/ source included

             

             

            this is a simple example of controlling the axis, the trick is that you need to listen for mousemove and mouseup at the application level otherwise mouseup would not release the drag if you moved off the dragged object.

             

             

            David.