# Relative mouse movement

**URL:** https://forum.kirupa.com/t/relative-mouse-movement/3399
**Category:** Uncategorized
**Created:** [February 15, 2002, 12:25am UTC](https://forum.kirupa.com/t/relative-mouse-movement/3399 "2002-02-15T00:25:52Z")
**Posts on this page:** 11
**Page:** 1

<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: [February 15, 2002, 12:25am UTC](https://forum.kirupa.com/t/relative-mouse-movement/3399/1 "2002-02-15T00:25:52Z")

</div>

if (\_root.\_xmouse\>\_level0.circle.\_x) {\r \_level0.circle.\_x = (\_level0.circle.\_x+10);\r} else {\r \_level0.circle.\_x = (\_level0.circle.\_x-10);\r}\r\r\rthis will make a movie follow the mouse … how can I make the movie move\rthe same distance away from the mouse so that the two are lined up in the\rmiddle but as I move the mouse to one side the movie travels and equal\rdistance to the other side. Any help anyone can give me would be great.

---

<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: [February 15, 2002, 5:14am UTC](https://forum.kirupa.com/t/relative-mouse-movement/3399/2 "2002-02-15T05:14:39Z")

</div>

in the movie you wish to exhibit this behaviour:

```auto
  \r\ronClipEvent(load){\r\r // where ever the centre is\r\r c = 200;\r\r}\r\r\r\ronClipEvent(mouseMove){\r\r _x = c - (_parent._xmouse -c);\r\r}

```

\r\r\* edit\*\r\rcan be simplified to:\r\_x = - \_parent.\_xmouse + c;

---

<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: [February 15, 2002, 8:50am UTC](https://forum.kirupa.com/t/relative-mouse-movement/3399/3 "2002-02-15T08:50:17Z")

</div>

Any particular reason why you use mouseMove instead of enterFrame ??\r\rpom 0]

---

<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: [February 15, 2002, 8:56am UTC](https://forum.kirupa.com/t/relative-mouse-movement/3399/4 "2002-02-15T08:56:09Z")

</div>

mouse move only checks when the mouse moves. Enter frame checks a number of times per second equal to your frame rate. Less for the processor to handle, I’d guess.

---

<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: [February 15, 2002, 11:58pm UTC](https://forum.kirupa.com/t/relative-mouse-movement/3399/5 "2002-02-15T23:58:33Z")

</div>

exactly upuaut.\r\rin this case, it doesn’t make much of a difference, but it’s a good practice to run code only when necessary.

---

<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: [February 18, 2002, 9:02pm UTC](https://forum.kirupa.com/t/relative-mouse-movement/3399/6 "2002-02-18T21:02:25Z")

</div>

I’m not sure I fully understand the code (not real good at this yet) but thanks, it gives me something to work with.

---

<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: [February 20, 2002, 12:53am UTC](https://forum.kirupa.com/t/relative-mouse-movement/3399/7 "2002-02-20T00:53:46Z")

</div>

great code, thanks Suprabeener. If you don’t mind could you break it down remedial for me? I’m very bad at this. It works for me already but i’m trying to understand it a little better.

---

<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: [February 20, 2002, 5:47am UTC](https://forum.kirupa.com/t/relative-mouse-movement/3399/8 "2002-02-20T05:47:24Z")

</div>

best way to understand would be to plug in numbers and see why it returns the result it does.\r\ryou set c to be the middle so it has something to be relative to, i’m assuming you’re all over that. only needs to be done once at the beginning so it goes well in an onClipEvent(load) handler.\r\reverytime the mouse moves we want the movie to react, onClipEvent(mouseMove) fits the bill nicely.\r\rthe \_x property refers to the x position of whatever’s to the left of it. a.\_x would refer to movie a’s x position. but wait, there’s nothing to the left of this \_x! since code that’s not preceded with \_root or \_level is relative to the clip it’s in, that means that \_x will refer to whichever clip you place the code in. so we’re setting the current clip’s \_x property.\r\rthe \_xmouse property refers to the mouse’s x position, whatever it may be. this is also a movie property and it’s relative to the movie specified just the same way as \_x or any other property. this is because each movie has it’s own 0,0. so if the mouse is right over movie a’s registration point (0,0), a.\_xmouse will return 0, whereas \_root.\_xmouse will return the mouse’s x position relative to \_root.\r\rin this case we’ve specified \_parent, which means whichever movie the current movie is in. in this case \_root.\r\rso let’s say that c was 200, and the mouse is at 268. plug those numbers in…\r\r\_x = 200 - (268-200);\r\rlets do the brackets…\r\r\_x = 200 - 68;\r\r\_x = 132;\r\rso the movie is moved to 132, which happens to be equi-distant from c as the mouse. see how this will always be the case?\r\rfun. fun. fun. ; )

---

<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: [February 20, 2002, 4:25pm UTC](https://forum.kirupa.com/t/relative-mouse-movement/3399/9 "2002-02-20T16:25:08Z")

</div>

wow, thank you very very much … that answered all of my questions. Thanks again.

---

<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: [July 20, 2004, 1:16am UTC](https://forum.kirupa.com/t/relative-mouse-movement/3399/10 "2004-07-20T01:16:40Z")

</div>

This is a great little mouse thing…

But… would you know how to imitate this?

Which by the way is an awesome site!

[http://www.kelamali.com/La\_Bibliotheque\_du\_Mande.html](http://www.kelamali.com/La_Bibliotheque_du_Mande.html)

Go there and look at some of the pictures.

Notice how the pictures move realtive the mouses position, but in the opposite direction just a few pixels…

Any ideas?

Any help would be awesome!

---

<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: [July 20, 2004, 1:47am UTC](https://forum.kirupa.com/t/relative-mouse-movement/3399/11 "2004-07-20T01:47:22Z")

</div>

Well, this is what I have so far… but I cannot make the vertical axis move…

Also, I would like to add easing… is that possible?

```auto
onClipEvent(load){

   // where ever the centre is

   c = 200;
   d = 150;
}

onClipEvent(mouseMove){

   _x = (c) - ((0.02 * _parent._xmouse) - c);
   //_y = (d) - ((0.02 * _parent._xmouse) - d);
}

```

Thanks again!
