I'm using greensock tweenlite to click, drag and rotate a circular movieclip and have the following so far.
What I need to do is determine the direction of the rotation and the speed, i.e. if the user is spinning the wheel to the right, store this direction in a string variable say and the rotation speed in a number variable.
I've tried numerous different things with the mousestart and move coordinates and with the vinyl_mc rotation coordinates but can't get anything reliable. Is there a way I can determine the direction and speed and store these in variables?
The app can be viewed at: http://s46264.gridserver.com/dev/dave/rotate/rotate.html and source fla is at: http://s46264.gridserver.com/dev/dave/rotate/rotate.fla.zip if this helps at all.
Thanks.
import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.plugins.*;
import flash.events.*;
TweenPlugin.activate([ShortRotationPlugin]);
var oldRotation,ax,ay,bx,by,thetaA,thetaB,delTheta,newTheta:Number;
var direction:String;
function dragger(evt:MouseEvent)
{
if (evt.type == MouseEvent.MOUSE_DOWN)
{
stage.addEventListener(MouseEvent.MOUSE_MOVE, dragger);
stage.addEventListener(MouseEvent.MOUSE_UP, dragger);
oldRotation = vinyl_mc.rotation;
ax = stage.mouseX - vinyl_mc.x;
ay = stage.mouseY - vinyl_mc.y;
thetaA = Math.atan2(ay,ax) * 180 / Math.PI;
if (thetaA < 0)
{
thetaA = - thetaA;
}
else
{
thetaA = 360 - thetaA;
}
}
else if (evt.type == MouseEvent.MOUSE_MOVE)
{
bx = stage.mouseX - vinyl_mc.x;
by = stage.mouseY - vinyl_mc.y;
thetaB = Math.atan2(by,bx) * 180 / Math.PI;
if (thetaB < 0)
{
thetaB = - thetaB;
}
else
{
thetaB = 360 - thetaB;
}
delTheta = thetaB - thetaA;
newTheta = oldRotation - delTheta;
TweenLite.to(vinyl_mc, 1, {shortRotation:{rotation:newTheta}, overwrite:true, ease:Cubic.easeOut});
}
else if (evt.type == MouseEvent.MOUSE_UP)
{
stage.removeEventListener(MouseEvent.MOUSE_MOVE, dragger);
stage.removeEventListener(MouseEvent.MOUSE_UP, dragger);
}
}
vinyl_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragger);