8 Replies Latest reply on Dec 14, 2011 8:18 AM by kglad

    Drag and Drop axis lock

    JohnnyVee1945

      I am creating animations in Flash 5.5 for use in Captivate 5.5.  I have created a drag-and-drop animation for a horizontal line and a vertical line, to act as moveable "straight edges" for use on complicated charts.  How do I lock the horizontal line to just move along the Y axis, and the Vertical line to just move along the X axis?  (I'm a relative newbir working in Flash.)  Thanks for any help.

       

      John

        • 1. Re: Drag and Drop axis lock
          EvilBartek Level 1

          I never used flash for stuff like that but are you using scripts?

          • 2. Re: Drag and Drop axis lock
            kglad Adobe Community Professional & MVP

            are you using as2 or as3?

            • 3. Re: Drag and Drop axis lock
              JohnnyVee1945 Level 1

              I am using AS3 script.  Here is the code I have from a Flash "Snippet":

               

              /* Drag and Drop

              Makes the specified symbol instance moveable with drag and drop.

              */

               

              movieClip_1.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag);

               

              function fl_ClickToDrag(event:MouseEvent):void

              {

                  movieClip_1.startDrag();

              }

               

              stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop);

               

              function fl_ReleaseToDrop(event:MouseEvent):void

              {

                  movieClip_1.stopDrag();

              }

               

              /* Click to Position an Object

              Moves the specified symbol instance to the x-coordinate and y-coordinate you specify.

               

              Instructions:

              1. Replace the value 200 with the x-coordinate

                 where you want to position the object.

              2. Replace the value 100 with the y-coordinate where you want to position the object.

              */

               

               

               

              /* Drag and Drop

              Makes the specified symbol instance moveable with drag and drop.

              */

               

              movieClip_2.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag_2);

               

              function fl_ClickToDrag_2(event:MouseEvent):void

              {

                  movieClip_2.startDrag();

              }

               

              stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop_2);

               

              function fl_ReleaseToDrop_2(event:MouseEvent):void

              {

                  movieClip_2.stopDrag();

              }

               

              Hope this helps.  Thanks for your interest.

               

              John

              • 4. Re: Drag and Drop axis lock
                JohnnyVee1945 Level 1

                I am using AS3 code.  Here is what I have so far, from a Flash "Snippet":

                 

                /* Drag and Drop

                Makes the specified symbol instance moveable with drag and drop.

                */

                 

                movieClip_1.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag);

                 

                function fl_ClickToDrag(event:MouseEvent):void

                {

                    movieClip_1.startDrag();

                }

                 

                stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop);

                 

                function fl_ReleaseToDrop(event:MouseEvent):void

                {

                    movieClip_1.stopDrag();

                }

                 

                /* Click to Position an Object

                Moves the specified symbol instance to the x-coordinate and y-coordinate you specify.

                 

                Instructions:

                1. Replace the value 200 with the x-coordinate

                   where you want to position the object.

                2. Replace the value 100 with the y-coordinate where you want to position the object.

                */

                 

                 

                 

                /* Drag and Drop

                Makes the specified symbol instance moveable with drag and drop.

                */

                 

                movieClip_2.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag_2);

                 

                function fl_ClickToDrag_2(event:MouseEvent):void

                {

                    movieClip_2.startDrag();

                }

                 

                stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop_2);

                 

                function fl_ReleaseToDrop_2(event:MouseEvent):void

                {

                    movieClip_2.stopDrag();

                }

                 

                Hope this helps.  Thanks for your interest.

                 

                John

                • 5. Re: Drag and Drop axis lock
                  kglad Adobe Community Professional & MVP

                  which movieclip is your vertical line and which is horizontal?

                  • 6. Re: Drag and Drop axis lock
                    JohnnyVee1945 Level 1

                    Clip 1 is the horizontal line that moves up and down in the Y axis, and clip 2 is the vertical line that moves side to side.

                     

                    That said, I think what I really need is a bounding box, which will achieve the same end, but also keep the lines from going outside the window with the chart, and wandering over the rest of the stage.  I would need a bounding box of 729 wide by 369 high.

                     

                    Thanks again.

                     

                    John

                    • 7. Re: Drag and Drop axis lock
                      iFlashAppsToo Level 3

                      or you could try something like this:

                       

                      movieClip_1.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag);

                      movieClip_2.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag);

                      var mc:MovieClip;

                       

                      function fl_ClickToDrag(event:MouseEvent):void

                      {

                          mc = event.target;

                          stage.addEventListener(MouseEvent.MOUSE_MOVE, moveMe);

                          stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop);

                      }

                       

                      function moveMe(event:MouseEvent){

                          if(mc == movieClip_1){

                               mc.y = mouseY;

                          }

                          else{

                               mc.x = mouseX;

                          }

                      }

                       

                      function fl_ReleaseToDrop(event:MouseEvent):void

                      {

                          stage.removeEventListener(MouseEvent.MOUSE_MOVE, moveMe);

                          stage.removeEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop);

                      }

                      • 8. Re: Drag and Drop axis lock
                        kglad Adobe Community Professional & MVP

                        use:

                         

                         

                         

                        /* Drag and Drop

                        Makes the specified symbol instance moveable with drag and drop.

                        */

                         

                        movieClip_1.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag);

                         

                        function fl_ClickToDrag(event:MouseEvent):void

                        {

                            movieClip_1.startDrag(false,new Rectangle(0,0,0,stage.stageHeight));

                        }

                         

                        stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop);

                         

                        function fl_ReleaseToDrop(event:MouseEvent):void

                        {

                            movieClip_1.stopDrag();

                        }

                         

                        /* Click to Position an Object

                        Moves the specified symbol instance to the x-coordinate and y-coordinate you specify.

                         

                        Instructions:

                        1. Replace the value 200 with the x-coordinate

                           where you want to position the object.

                        2. Replace the value 100 with the y-coordinate where you want to position the object.

                        */

                         

                         

                         

                        /* Drag and Drop

                        Makes the specified symbol instance moveable with drag and drop.

                        */

                         

                        movieClip_2.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag_2);

                         

                        function fl_ClickToDrag_2(event:MouseEvent):void

                        {

                           movieClip_2.startDrag(false,new Rectangle(0,0,stage.stageWidth,0));

                        }

                         

                        stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop_2);

                         

                        function fl_ReleaseToDrop_2(event:MouseEvent):void

                        {

                            movieClip_2.stopDrag();

                        }

                         

                        Hope this helps.  Thanks for your interest.

                         

                        John

                        1 person found this helpful