1

I have a dial that rotates 120 degrees clockwise and 120 degrees anti clockwise using the rotate TransformGestureEvent.

When rotating this dial I want it to control a movie clip. Dragging through the movieclip as you rotate the dial clockwise then reversing the movieclip when rotating the dial anticlockwise. I want the movieclip to follow the drag of the dial, stopping and starting as and when you drag the dial.

Here is what I have so far but it only seems to turn the movieclip to the last frame then stops?

    import flash.display.MovieClip;
    var dial_mc:MovieClip;
    var knobs_mc:MovieClip;
    var maxRotation:Number = 120;

    var knobFrame:int = knobs_mc.currentFrame;
    var offset:Number = 0;
    var percent:Number = 0;


    knobs_mc.stop();

    Multitouch.inputMode = MultitouchInputMode.GESTURE;

    dial_mc.addEventListener(TransformGestureEvent.GESTURE_ROTATE, rotateDial);

    function rotateDial(e:TransformGestureEvent):void
    {
dial_mc.rotation +=  e.rotation;
if (dial_mc.rotation > maxRotation)
{
    dial_mc.rotation = maxRotation;
}
if (dial_mc.rotation < 0)
{
    dial_mc.rotation = 0;
}
dial_mc.addEventListener(TransformGestureEvent.GESTURE_ROTATE, drag);
offset = e.rotation;
if (e.phase == GesturePhase.END)
{
    knobFrame = knobs_mc.currentFrame;

}


function drag(e:TransformGestureEvent):void
{

    percent =  (e.rotation - offset)/knobs_mc.rotation;

    var frame:int = Math.round(percent * knobs_mc.totalFrames) + knobFrame;

    while (frame > knobs_mc.totalFrames)
    {
        frame -=  knobs_mc.totalFrames;
    }

    while (frame <= 0)
    {
        frame +=  knobs_mc.totalFrames;
    }

    knobs_mc.gotoAndStop(frame);
}
    }
Danielle
  • 53
  • 7

1 Answers1

1

You have to adjust your math to map the angles from -120 to 120 to 0 to 240. That way when you try to go to a frame you can get the full range. I'm assuming that frame 1 - 120 have the dial pointing on the left.

One other approach would be to ditch the frames altogether and work with rotating the dial directly using the angle.

Gone3d
  • 1,189
  • 1
  • 8
  • 20
  • dial_mc just uses gesture Roation and does not have frames but i want this to rotate and in turn play and stop knobs_mc. – Danielle Nov 28 '12 at 14:26
  • Im very new to AS3 so im just working on trial and error i dont really have all the knowledge yet! But basically dial_mc is a head on shot of a large dial that when turned will activate a smaller image of the dial on its side (knobs_mc) in knobs_mc is s eries of 5 shots that when played together animate as if they are being turned. Does this make sense? – Danielle Nov 28 '12 at 14:29
  • You are adding the rotation to the current value - is that what you want? Does the event show the change in rotation or does it give the current rotation? In any case the max rotation should be 240 and if you're starting at 0 rotation, the dial should be 120. However, flash also uses Radians, so getting the rotation back in degrees from the event handler, you'll need to convert them to radians and add them to the rotation. Again, check your math, either using the debugger or traces to see what values you're getting. – Gone3d Nov 28 '12 at 14:34
  • No thats not what i want, The rotation part is all thats working. I believe im going the wrong way about everything else. I want the rotation limited to 120 clockwise and 120 anticlockwise which i achieve with maxRotation. But im completely stuck on what im doing with the rest. – Danielle Nov 28 '12 at 15:06
  • But you want a total of 240° but you're limiting it to 120° - that's why I said you need to remap it. – Gone3d Nov 28 '12 at 15:11
  • Sorry i havent explained myself correctly, it rotates to 120 clockwise and then rotates anticlockwise back to 0, How now do i get the movieclip to play in sync? – Danielle Nov 28 '12 at 16:00
  • ok - so it only goes 120° then have a function map the angle to the frame number by determining the Scaling factor. (num of frames/degree) * degrees. num of frames would be the total number of frames comprising the range in the MovieClip – Gone3d Nov 28 '12 at 17:36
  • Im still confused, like i said im very new to writting code and only learnt the basics a month ago. Any chance you write out code with explanations for me? I want to learn :) – Danielle Nov 29 '12 at 09:01
  • Wow, scrap that i think ive cracked it! Thank you for your help makes sense now! :) – Danielle Nov 29 '12 at 09:13