# Change Movieclip frame depending on mouse position AS2?

**URL:** <https://forum.kirupa.com/t/change-movieclip-frame-depending-on-mouse-position-as2/329244>\
**Category:** programming\
**Created:** [August 5, 2012, 9:22pm UTC](https://forum.kirupa.com/t/change-movieclip-frame-depending-on-mouse-position-as2/329244 "2012-08-05T21:22:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Buffy1011](https://avatars.discourse-cdn.com/v4/letter/b/e95f7d/32.png) [@Buffy1011](https://forum.kirupa.com/u/Buffy1011)\
**Post date:** [August 5, 2012, 9:22pm UTC](https://forum.kirupa.com/t/change-movieclip-frame-depending-on-mouse-position-as2/329244/1 "2012-08-05T21:22:47Z")

</div>

Hi!  
Okay, so, I’ve been scoring the internet for help or ideas or SOMETHING to help me figure this out…So, I have a movieclip with 4 frames: one for northwest, one for southwest, one for southeast, one for northeast. What I want that movie clip to do is, well, walk.  
When it walks, I want to switch the frames depending on the position of the mouse…i.e., if its in the bottom-left corner, the movieclip switches to the specific frame.  
I’m sure this has been posted about before, but I COULDN’T FIND ANYTHING that’s helpful to this. So, sorry if I’m reposting…  
This is the current code I have. It’s currently kind of glitchy…Just rotates the avatar based on the specific mouse position, walking’s not added yet or anything.

```auto
checkX = function (dx, oldVal, newVal) {
if (oldVal<newVal) {
_root.avatar.gotoAndStop(4);
} else if (oldVal>newVal) {
_root.avatar.gotoAndStop(3);
}
return newVal;
};
checkY = function (dy, oldVal, newVal) {
if (oldVal<newVal) {
_root.avatar.gotoAndStop(2);
} else if (oldVal>newVal) {
_root.avatar.gotoAndStop(1);
}
return newVal;
};
this.watch("xdir", checkX);
this.watch("ydir", checkY);
this.onMouseMove = function() {
xdir = _xmouse;
ydir = _ymouse;
};

```

How would I fix it to do what I want? Any tutorials anyone knows of that I may have missed?  
Thanks a lot, hoping for a reply ASAP 🙂
