# Easing to a position

**URL:** <https://forum.kirupa.com/t/easing-to-a-position/185284>\
**Category:** flash\
**Created:** [April 12, 2006, 6:19am UTC](https://forum.kirupa.com/t/easing-to-a-position/185284 "2006-04-12T06:19:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pixelMaven](https://avatars.discourse-cdn.com/v4/letter/p/a3d4f5/32.png) [@pixelMaven](https://forum.kirupa.com/u/pixelMaven)\
**Post date:** [April 12, 2006, 6:19am UTC](https://forum.kirupa.com/t/easing-to-a-position/185284/1 "2006-04-12T06:19:08Z")

</div>

Hi, and thanks to anyone in advance who knows how to solve this. I am creating a vertical menu with sub-links, which expand out once the main link is pressed, pushing all the buttons below them downwards (with easing). Except when i give one of the links a \_y position to ease to, it never fully makes it to it, by under 1 pixel, leaving it slightly blurred.

For example, i want to ease one of the buttons below the clicked-on button to \_y = 300. but it eases to 299.5.

the equation for this is…

onClipEvent (enterFrame) {  
dist = \_root.link\_03\_pos - this.\_y;  
travel = dist / \_root.speed;  
this.\_y += travel;  
}

\_root.link\_03\_pos is passed a new \_y position when any button is pressed.

Why, when the dist is smaller than 1, does flash stop moving the mc?

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [April 12, 2006, 6:29am UTC](https://forum.kirupa.com/t/easing-to-a-position/185284/2 "2006-04-12T06:29:22Z")

</div>

Because that equation never evaluates to zero. You could divide the distance by the speed infinitely and it would never in your wildest dreams equal zero (only very, very close).

Solution is something like this:

```auto
onClipEvent (enterFrame) {
 if (Math.abs(_root.link_03_pos) - Math.abs(this._y) > 1) {
  this._y += (_root.link_03_pos - this._y) / _root.speed;
 } else {
  this._y = _root.link_03_pos;
 }
}

```

🙂

---

<div class="post-metadata">

**Author:** ![pixelMaven](https://avatars.discourse-cdn.com/v4/letter/p/a3d4f5/32.png) [@pixelMaven](https://forum.kirupa.com/u/pixelMaven)\
**Post date:** [April 12, 2006, 7:16am UTC](https://forum.kirupa.com/t/easing-to-a-position/185284/3 "2006-04-12T07:16:35Z")

</div>

Thanks canadian, one thing i dont quite understand is, why would flash stop dividing below 1? fair enough that it would never equal 0, but, say for example the dist got down to 0.8, which was then divided by 10 (\_root.speed), making the travel 0.08, in turn making the new \_y position 0.72?  
But it just dosent do this? its like it simply stops below 1? Or is it simply a coincendence with something im missing?

Also, your script only works one way, once the [COLOR=#000000][/COLOR][COLOR=#0000FF]_root[/COLOR].[COLOR=#000080]link_[/COLOR][COLOR=#000080]03[/COLOR]\_pos is smaller than this.\_y, its a negative dist and just jumps to the new position, rather than easing.

Thanks for helping, its really appreciated. :thumb:

---

<div class="post-metadata">

**Author:** ![Macaroni\_Ted](https://avatars.discourse-cdn.com/v4/letter/m/df788c/32.png) [@Macaroni\_Ted](https://forum.kirupa.com/u/Macaroni_Ted)\
**Post date:** [April 12, 2006, 9:28am UTC](https://forum.kirupa.com/t/easing-to-a-position/185284/4 "2006-04-12T09:28:36Z")

</div>

you dont need the two Math.abs() methods in the ‘if’ statement. if you use just the one it’ll work for either start and end point.  
[AS]  
onClipEvent (enterFrame) {  
if (Math.abs(\_root.link\_03\_pos-this.\_y)\> 1) {  
this.\_y += (\_root.link\_03\_pos - this.\_y) / \_root.speed;  
} else {  
this.\_y = \_root.link\_03\_pos;  
}  
}  
[/AS]  
[COLOR=#000000][/COLOR]
