# \[FMX\] Trouble with rotation and elasticity

**URL:** <https://forum.kirupa.com/t/fmx-trouble-with-rotation-and-elasticity/30470>\
**Category:** flash\
**Created:** [September 9, 2003, 8:02am UTC](https://forum.kirupa.com/t/fmx-trouble-with-rotation-and-elasticity/30470 "2003-09-09T08:02:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Baron\_Ruhstoff](https://avatars.discourse-cdn.com/v4/letter/b/c0e974/32.png) [@Baron\_Ruhstoff](https://forum.kirupa.com/u/Baron_Ruhstoff)\
**Post date:** [September 9, 2003, 8:02am UTC](https://forum.kirupa.com/t/fmx-trouble-with-rotation-and-elasticity/30470/1 "2003-09-09T08:02:14Z")

</div>

Hey folks. I’m new to the forum and in need of some advice. I have a clip that rotates to orient itself towards the mouse when the mouse is over a given area. When the mouse leaves the area, the clip snaps back to its original position.

There are a few problems that I need help with:

1. the clip snaps directly towards the mouse at the moment the mouse enters the clip; I would like it to actually rotate;
2. the clip snaps directly back to its original position when the mouse leaves the clip; I would like it to ease back into position.

The code I am working with is below. I am currently using an easing function supplied by Robert Penner, but would be happy to try something else. Perhaps the real problem I am having is attaching functions to objects…

gearMC.anchor = 90  
gearMC.startRotation = gearMC.\_rotation;

hitAreaMC.onEnterFrame = function() {  
if (hitAreaMC.hitTest(\_root.\_xmouse, \_root.\_ymouse)) {  
gearMC.\_rotation = Math.atan2(\_ymouse-gearMC.\_y, \_xmouse-gearMC.\_x)\*180/Math.PI;  
}  
else {  
gearMC.\_rotation = gearMC.anchor;  
}  
}

//Easing code courtesy of Robert Penner

Math.easeOutElastic = function (t, b, c, d, a, p) {  
if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d\*.3;  
if (a \< Math.abs©) { a=c; var s=p/4; }  
else var s = p/(2_Math.PI) \* Math.asin (c/a);  
return a_Math.pow(2,-10_t) \* Math.sin( (t_d-s)_(2_Math.PI)/p ) + c + b;  
};
