# Stop rotating knob

**URL:** https://forum.kirupa.com/t/stop-rotating-knob/105745
**Category:** Uncategorized
**Created:** [March 29, 2004, 3:02pm UTC](https://forum.kirupa.com/t/stop-rotating-knob/105745 "2004-03-29T15:02:37Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![luth](https://avatars.discourse-cdn.com/v4/letter/l/9d8465/32.png) [@luth](https://forum.kirupa.com/u/luth)
#### Post date: [March 29, 2004, 3:02pm UTC](https://forum.kirupa.com/t/stop-rotating-knob/105745/1 "2004-03-29T15:02:37Z")

</div>

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&lt;-135) {
		r0._rotation = -135;
		this.drag = false;
	}
	
	if (r0._rotation&gt;135) {
		r0._rotation = 135;
		this.drag = false;
	}

```

\_root.rot = this.\_rotation;  
}  
}
