Relative mouse movement

if (_root._xmouse> {\r = (;\r} else {\r = (;\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.

in the movie you wish to exhibit this behaviour:

  \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;

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

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.

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.

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

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.

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. ; )

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

This is a great little mouse thing…

But… would you know how to imitate this?

Which by the way is an awesome site!

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!

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?


   // where ever the centre is

   c = 200;
   d = 150;


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

Thanks again!