# \[Flash CS3 AS2\] Problem with motion based on \_xmouse

**URL:** https://forum.kirupa.com/t/flash-cs3-as2-problem-with-motion-based-on--xmouse/281658
**Category:** flash
**Created:** [February 11, 2009, 10:03pm UTC](https://forum.kirupa.com/t/flash-cs3-as2-problem-with-motion-based-on--xmouse/281658 "2009-02-11T22:03:21Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![station8](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/station8/32/2345_2.png) [@station8](https://forum.kirupa.com/u/station8)
#### Post date: [February 11, 2009, 10:03pm UTC](https://forum.kirupa.com/t/flash-cs3-as2-problem-with-motion-based-on--xmouse/281658/1 "2009-02-11T22:03:21Z")

</div>

Hi All,

So I’m stuck and going nuts. I need to move a movieclip based on mouse x position. Like this site [http://annieegiancasting.com/](http://annieegiancasting.com/) - Which I built using a flashloaded app, but I need more control in this project so I’d like to code it without the app.

Basically, I have an image of a boy (left) and a girl (right) and I want to move the boy slightly toward the girl when the mouse goes right and slightly away when the mouse goes left. But only about 25-50 pixels in each direction.

I’ve cobbled some code together from google searching and rough ideas, and it works in a way, but the boy jumps about 400 pixels to the left on the initial mouse move and then floats a bit too far right and left from there.

Here’s what I’ve got on the boyMC:

```auto
onClipEvent (enterFrame) {
	MouseX = (_root._xmouse);
	thisX = this._x;
	diffX = MouseX - thisX;
	moveX = diffX / 30;
	this._x = thisX + moveX;
}

```

The movement has a nice ease to it and does roughly what I want but something is missing. Any help on this would be greatly, greatly appreciated. Thanks in advance!!
