# \[AS1\] Mouse Speed Detection Problem!

**URL:** <https://forum.kirupa.com/t/as1-mouse-speed-detection-problem/62653>\
**Category:** flash\
**Created:** [August 30, 2004, 8:32am UTC](https://forum.kirupa.com/t/as1-mouse-speed-detection-problem/62653 "2004-08-30T08:32:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![blue\_chi](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/blue_chi/32/62_2.png) [@blue\_chi](https://forum.kirupa.com/u/blue_chi)\
**Post date:** [August 30, 2004, 8:32am UTC](https://forum.kirupa.com/t/as1-mouse-speed-detection-problem/62653/1 "2004-08-30T08:32:33Z")

</div>

I’ve been facing this problem for years and I finally decided to try and find the answer to it. I use something like this code to detect the speed of the movement of a dragged object

```php
if (!go) {
		this["position_"+i] = this._y;
		i++;
		if (i == 3) {
			i = 1;
		}
		delta_y = this.position_2-this.position_1;
	}

```

This way I can find in what direction the mouse vertically has moved and at what speed. The problem is that every once in a while the speed will be in the opposite direction. What do people use to detect the direction of the movement of the mouse?  
😕

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 30, 2004, 4:51pm UTC](https://forum.kirupa.com/t/as1-mouse-speed-detection-problem/62653/2 "2004-08-30T16:51:06Z")

</div>

_Shouts out_ = HELP!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 30, 2004, 10:11pm UTC](https://forum.kirupa.com/t/as1-mouse-speed-detection-problem/62653/3 "2004-08-30T22:11:15Z")

</div>

what do you mean in the opposite direction? if you’re just wnating to find the speed the mouse is moving you couls use some basic pythagoras. this will work no matter what way you move the mouse:

```auto
onClipEvent(load) {
	prevX = _root._xmouse;
	prevY = _root._ymouse;
}
onClipEvent(enterFrame) {
	x = _root._xmouse - prevX;
	y = _root._ymouse - prevY;
	speed = Math.sqrt((x*x) + (y*y));
	trace(speed);
	prevX = _root._xmouse;
	prevY = _root._ymouse;
}

```

hope this helps you.
