5 Replies Latest reply on May 6, 2009 5:41 PM by kglad

    Drag rotation

    iinfinity8 Level 1

      Hey, is there a way to make a movie clip so you can drag it as if it was constrained to a center point and rotates around in a circle?

       

      Thanks

        • 1. Re: Drag rotation
          kglad Adobe Community Professional & MVP

          no, but you can make it appear that the movieclip is being dragged in a circle by starting a loop and updating the movieclips position as the mouse moves.

          • 2. Re: Drag rotation
            iinfinity8 Level 1

            ok and how would i go about doing that?

            • 3. Re: Drag rotation
              kglad Adobe Community Professional & MVP

              that's hard to say because the exact coding varies substantially depending on whether you're using as2 or as3.  although once you start your loop the function that updates the movieclip's position will look very similar in both.

              • 4. Re: Drag rotation
                iinfinity8 Level 1

                Ok, im using Actionscript 2 and am i understanding you right if i say what i should do is make a movie clip of the object rotating 360 degrees then add code relating to the mouse position which tells it how far to rotate? cna you give me an example of the code please?

                • 5. Re: Drag rotation
                  kglad Adobe Community Professional & MVP

                  no, just make movieclip and give it an instance name, say mymc:

                   

                   

                  mymc.onPress = function(){
                       startCircleDragF(this,200,200,150);  // drag this around a circle with radius 150 centered at 200,200
                  }
                  mymc.onRelease = mc.onReleaseOutside = stopCircleDragF;
                  
                  
                  //  nothing below here needs to be changed
                  function startCircleDragF(mc:MovieClip,x:Number,y:Number,radius:Number){
                       clearInterval(mc.circleDragI);
                       mc.circleDragI=setInterval(circleDragF,50,mc,x,y,radius);
                  }
                  function stopCircleDragF(){
                       clearInterval(this.circleDragI);
                  }
                  function circleDragF(mc:MovieClip,x:Number,y:Number,radius:Number){
                       var ang:Number = Math.PI+Math.atan2(y-_ymouse,x-_xmouse);
                       mc._x = x+radius*Math.cos(ang);
                       mc._y = y+radius*Math.sin(ang);
                       updateAfterEvent();
                  }