I am using the attached knob from a Kirupa post I found but I need it to stop rotating when it gets to 135 or -135. I have it working somewhat now but if you move the mouse quickly across the bottom of the knob it will jump to the other side. Does anyone know a way to stop it? Ideally I would like to be able to make it stop rotating without using stop drag at all.
r0.speed = Math.random()-.5;
r0.onPress = doDrag;
r0.onRelease = noDrag;
r0.onReleaseOutside = noDrag;
r0.onEnterFrame = move;
function doDrag() {
this.drag = true;
var dx = _xmouse-this._x;
var dy = _ymouse-this._y;
this.angle = Math.atan2(dy, dx);
}
function noDrag() {
this.drag = false;
}
function move() {
if (this.drag) {
var dx = _xmouse-this._x;
var dy = _ymouse-this._y;
var newAngle = Math.atan2(dy, dx);
this.speed = newAngle-this.angle;
this.angle = newAngle;
this._rotation += this.speed*180/Math.PI;
//if mouse goes past 135 or -135 stop
if (r0._rotation<-135) {
r0._rotation = -135;
this.drag = false;
}
if (r0._rotation>135) {
r0._rotation = 135;
this.drag = false;
}
_root.rot = this._rotation;
}
}