# Avoid mouse

**URL:** <https://forum.kirupa.com/t/avoid-mouse/10501>\
**Category:** flash\
**Created:** [January 2, 2003, 12:38pm UTC](https://forum.kirupa.com/t/avoid-mouse/10501 "2003-01-02T12:38:35Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![thebull](https://avatars.discourse-cdn.com/v4/letter/t/8dc957/32.png) [@thebull](https://forum.kirupa.com/u/thebull)\
**Post date:** [January 2, 2003, 12:38pm UTC](https://forum.kirupa.com/t/avoid-mouse/10501/1 "2003-01-02T12:38:35Z")

</div>

Hello,

as someone have a script to attach to mc´s, that avoids the mouse?

thanks

---

<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:** [January 2, 2003, 1:55pm UTC](https://forum.kirupa.com/t/avoid-mouse/10501/2 "2003-01-02T13:55:00Z")

</div>

```auto

MovieClip.prototype.avoidMouse = function(distance, speed, accel){
	var xdiff = this._parent._xmouse - this._x;
	var ydiff = this._parent._ymouse - this._y;
	var dist = Math.sqrt(xdiff*xdiff + ydiff*ydiff);
	if (dist < distance){
		var angle = Math.atan2(ydiff, xdiff);
		if (accel) speed = Math.min(speed, accel*distance/dist);
		this._x -= Math.cos(angle)*speed;
		this._y -= Math.sin(angle)*speed;
	}
}

// usage:
myMovieClip.onEnterFrame = function(){
	this.avoidMouse(100, 10, 5);
}

```

accel is optional. If accel is used, speed defaults as the top speed. Otherwise, without accel, the speed of the clip is constant as it avoids the mouse until it reaches \>= distance.

---

<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:** [January 2, 2003, 2:01pm UTC](https://forum.kirupa.com/t/avoid-mouse/10501/3 "2003-01-02T14:01:53Z")

</div>

did you make it senocular?  
🙂

---

<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:** [January 2, 2003, 2:14pm UTC](https://forum.kirupa.com/t/avoid-mouse/10501/4 "2003-01-02T14:14:05Z")

</div>

yeah 🙂

---

<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:** [January 2, 2003, 2:18pm UTC](https://forum.kirupa.com/t/avoid-mouse/10501/5 "2003-01-02T14:18:14Z")

</div>

did you make that just now, or you already have done this in a previous experiment?

sorry for asking, but this is a nice piece of code you got there, and doing that in that little time baffles me :!:

---

<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:** [January 2, 2003, 2:26pm UTC](https://forum.kirupa.com/t/avoid-mouse/10501/6 "2003-01-02T14:26:16Z")

</div>

I did it just now. Ive used it before a year or two ago but its hidden away in some file somewhere lost on my hard drive. It was easier to re-write it just now. I doubt its exactly the same thing I used before, but its the same concept none the less.

---

<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:** [January 2, 2003, 2:36pm UTC](https://forum.kirupa.com/t/avoid-mouse/10501/7 "2003-01-02T14:36:05Z")

</div>

😉

Yeah… we won’t let them know who forwarded you that code just a few minutes ago…

we’ll keep that OUR little secret. If you want them to think that YOU wrote it, that’s fine… we both know who did.

😉

:😆: :beam:

---

<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:** [January 2, 2003, 2:39pm UTC](https://forum.kirupa.com/t/avoid-mouse/10501/8 "2003-01-02T14:39:22Z")

</div>

> \*Originally posted by senocular \*  
> \*\*I did it just now. Ive used it before a year or two ago but its hidden away in some file somewhere lost on my hard drive. It was easier to re-write it just now. I doubt its exactly the same thing I used before, but its the same concept none the less. \*\*

congrats for you coding skills!

don´t go far, I might need your expert advice one of these days=)

---

<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:** [January 2, 2003, 10:20pm UTC](https://forum.kirupa.com/t/avoid-mouse/10501/9 "2003-01-02T22:20:19Z")

</div>

thanks for the script, it is possible to enter thw widht and height of the movie?

what i´m trying to do is this, in attach is the file

thanks

---

<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:** [January 2, 2003, 10:58pm UTC](https://forum.kirupa.com/t/avoid-mouse/10501/10 "2003-01-02T22:58:54Z")

</div>

thats not avoiding the mouse. Thats just repositioning on a rollover. Something to the effect of

---

<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:** [January 2, 2003, 11:18pm UTC](https://forum.kirupa.com/t/avoid-mouse/10501/11 "2003-01-02T23:18:39Z")

</div>

I must say, that this site since I discouver it (last 3 days) , is the best one.

Thanks for the script

you or other guru must wright a tutorial about this.

thanks

bull

---

<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:** [January 2, 2003, 11:21pm UTC](https://forum.kirupa.com/t/avoid-mouse/10501/12 "2003-01-02T23:21:01Z")

</div>

it is possible to insert one word on each rect?

:))))

---

<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:** [January 2, 2003, 11:49pm UTC](https://forum.kirupa.com/t/avoid-mouse/10501/13 "2003-01-02T23:49:35Z")

</div>

here you run into some problems since all the rectangles (in this example) are all of fixed size. It depends on how exactly you plan to format your moving ‘boxes’ - whether they will all have a sort or consistency or if they will be fairly random and of differing variations such as the example you posted. Chances are, each one of those were made manually and the script added to them individually. I myself dont like that monotonous work so I try to do as little as possible (as the example I posted used only the script on that one movieclip). But for altering that example, all you would have to do is include a textfield in Symbol 1 and give it a name like avoid\_txt then in the script have something like… well heck Ill just post a new one, its not much different 😉 but the point is, if you want a lot of different sizes and variety, skip the whole duplication thing and just make them manually. If you want, I can show you away to control all the movieclips within another so you wont have to add any script to any of the unique movieclips youve made - all you would have to do is throw them in a containing movieclip and put some script on that which will work the magic on all the clips within it (assuming they are all supposed to perform the same operations).

---

<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:** [January 3, 2003, 3:25pm UTC](https://forum.kirupa.com/t/avoid-mouse/10501/14 "2003-01-03T15:25:42Z")

</div>

i will give a shot.

thanks
