Follow mouse, detect direction, distance to, play corresponding MC frame

Hello,
Second time poster and a novice in actionscript.
I can almost read it, just can’t seem to write it at all.

I’m trying to have the animation of a MC instance name “walking_mc” follow the mouse on the x axis, arrive at the mouse and stop, turn then continue following the mouse in which ever direction it moves.
here’s a link to the file:
http://jdittmer.free.fr/test/test.htm
http://jdittmer.free.fr/test/walking.fla.zip

here is what I have so far:

[AS]

function fMoveChar() {

    var xmouse = _root._xmouse;
    var xchar = myCharacter._x;
    
    if (xmouse > xchar) var dir = 1;
    else var dir = -1
    
    myCharacter._x += myCharacter.speed * dir;
    
    var dist = Math.abs(xchar - xmouse);
    
    // use conditional statements and the dist variable to tell your mc to goto certain frames
	
	
	 if (dist < 15) {
        
            myCharacter.gotoAndPlay("StopFromRight");

    
    } else myCharacter.speed = 4;
	
	  if (dist < 2) {
            myCharacter.speed = 0;
            myCharacter._x = xmouse;
    
    } else myCharacter.speed = 4;

}

moveInt = setInterval(fMoveChar,44);

[AS]

I have an MC with the corresponding frames and the appropriate frame names ie; “LeftToRight”, “StopFromRight”, “LeaveToLeft”;
I’m looking for the actionscript for that will allow it to:

  • detect whether the _xmouse is to the left or the right and play the corresponding frame.
    An if/else with the dist variable would give me part, but not direction.
    I’d appreciate any help you all could give.
    Thanks,
    JED