# Actionscript 2.0 - flip horizontal when mouse direction changes

**URL:** https://forum.kirupa.com/t/actionscript-2-0-flip-horizontal-when-mouse-direction-changes/280967
**Category:** flash
**Created:** [February 3, 2009, 3:50pm UTC](https://forum.kirupa.com/t/actionscript-2-0-flip-horizontal-when-mouse-direction-changes/280967 "2009-02-03T15:50:24Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![fiona\_young](https://avatars.discourse-cdn.com/v4/letter/f/c77e96/32.png) [@fiona\_young](https://forum.kirupa.com/u/fiona_young)
#### Post date: [February 3, 2009, 3:50pm UTC](https://forum.kirupa.com/t/actionscript-2-0-flip-horizontal-when-mouse-direction-changes/280967/1 "2009-02-03T15:50:24Z")

</div>

I have tried the following code to make a movie clip (car\_mc) follow the mouse and to flip horizontally when the mouse changes direction. Some of it works well but the flip is unstable. I have also tried using -1 for both flips. Any suggestions as to what I am doing wrong? Thanks.

//check horizontal direction of moving mouse  
checkX = function (dx, oldVal, newVal) {  
if (oldVal\<newVal) {  
trace(“moving right”);  
car\_mc.\_xscale\*=1;  
}  
else if (oldVal\>newVal) {  
trace(“moving left”);  
car\_mc.\_xscale\*=-1;  
}  
return newVal;  
};  
this.watch(“xdir”, checkX);  
this.watch(“ydir”, checkY);  
this.onMouseMove = function() {  
xdir = \_xmouse;  
ydir = \_ymouse;  
};  
//make car follow mouse, and change direction with mouse  
car\_mc.onEnterFrame = function() {  
var xMouse = \_root.\_xmouse;

if(Math.abs(xMouse - this.\_x) \< 1) {  
this.\_x = xMouse;  
}  
else {  
this.\_x -= (this.\_x-xMouse) / 6;  
}  
}
