3 Replies Latest reply: Dec 28, 2010 1:25 PM by Andrei1 RSS

    how to drag object in a circular path?

    polatkanfatih Community Member

      hi,

       

      i want to drag and drop movieclip, but its restricted path should be circular instead of rectangle. is it possible by code.

       

      thanks....

        • 1. Re: how to drag object in a circular path?
          kglad CommunityMVP

          not really but you can fake it by using a loop to update the object's x,y properites and simulate a circular drag path.

          • 2. Re: how to drag object in a circular path?
            Andrei1 Community Member

            This code restrict arrow movement to a circle only (like a dial). It can be adjusted to establish boundaries within circle:

             

            var dial:Sprite;
            var dialRadius = 100;
            var arrow:Sprite;
            var angleConvert:Number = 180 * angle / Math.PI;
             
            init();
             
            function init():void 
            {
                 dial = new Sprite();
                 dial.x = dial.y = 150;
                 var g:Graphics = dial.graphics;
                 g.lineStyle(1, 0x004000);
                 g.drawCircle(0, 0, dialRadius);
                 addChild(dial);
                 
                 arrow = new Sprite();
                 arrow.buttonMode = arrow.useHandCursor = true;
                 g = arrow.graphics;
                 g.beginFill(0x000080);
                 g.moveTo(0, -15);
                 g.lineTo(7, 6);
                 g.lineTo( -7, 6);
                 g.endFill();
                 
                 arrow.y = -dialRadius;
                 dial.addChild(arrow);
                 arrow.addEventListener(MouseEvent.MOUSE_DOWN, onArrowDown);
            }
             
            function onMove(e:MouseEvent):void 
            {
                 var angle:Number = Math.atan2(mouseY - dial.y, mouseX - dial.x);
                 arrow.x = dialRadius * Math.cos(angle);
                 arrow.y = dialRadius * Math.sin(angle);
                 arrow.rotation = angleConvert * angle + 90;
            }
             
            function onArrowDown(e:MouseEvent):void 
            {
                 stage.addEventListener(MouseEvent.MOUSE_MOVE, onMove);
                 stage.addEventListener(MouseEvent.MOUSE_UP, onArrowUp);
            }
             
            function onArrowUp(e:MouseEvent):void 
            {
                 stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMove);
                 stage.removeEventListener(MouseEvent.MOUSE_UP, onArrowUp);
            }
            
            • 3. Re: how to drag object in a circular path?
              polatkanfatih Community Member

              i will try it...

               

              thanks...