Code: Select all
onClipEvent(enterFrame)
{
onMouseDown = function() {
onMouseMove = function() { //only executed if mouse button is down
if (_parent.area_mc.hitTest( _root._xmouse, _root._ymouse, true)) { //this determines if the mouse pointer is within legitimate area, other-
//wise it would be rotating every time the mouse is clicked anywhere.
var point:Object = {x:this._width/2, y:this._height/2};
this.localToGlobal(point);
//defines central point of the wheel and changes it to be displayed in global coordinates.
var Dy:Number = _root._ymouse - point.y; // y distance from center
var Dx:Number = _root._xmouse - point.x; // x distance from center
var a:Number; //angle in radians
if (Dx<1>-1) //there was an error here
{
if (Dy>0) {a = Math.PI/4;}
else if (Dy<0) {a = 3*Math.PI/4;}
else {a = 0;} //crossing the central point
}
else
{
a = Math.atan(Dy/Dx);
if (Dx<0) {a = a + Math.PI;}
}
this._rotation = a * 180/Math.PI;
} //End if hit target true
}; //end on mouse move
}; //end on mousedown
onMouseUp = function() {
// checking should only be done when mouse is pressed
delete onMouseMove;
};
}
I've gone through this in another program and although there was some jumpiness as well, I think it was only caused by exceding the 90 degree angle. But that was a bigger wheel.
EDIT: I bet it's all wrong defining x and y solely from the dimensions, that doesn't make any sense at all! The only way it would make sense is to have the registration point in the upper corner and then adding half the height and half the width to the dimensions, to come up with the central point.