# Actionscript for acceleration, constant movement, and deceleration

**URL:** <https://forum.kirupa.com/t/actionscript-for-acceleration-constant-movement-and-deceleration/180510>\
**Category:** flash\
**Created:** [March 1, 2006, 5:52am UTC](https://forum.kirupa.com/t/actionscript-for-acceleration-constant-movement-and-deceleration/180510 "2006-03-01T05:52:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![marc0047](https://avatars.discourse-cdn.com/v4/letter/m/ce73a5/32.png) [@marc0047](https://forum.kirupa.com/u/marc0047)\
**Post date:** [March 1, 2006, 5:52am UTC](https://forum.kirupa.com/t/actionscript-for-acceleration-constant-movement-and-deceleration/180510/1 "2006-03-01T05:52:48Z")

</div>

I’m trying to make a box move from left to right with the press of a button. However, the details of this movement is such:

1. Upon pressing a button, the box accelerates (easing motion) from 0 to 5 pixels per frame.
2. Once the easing hits 5 pixels per frame, I want the box to hold that motion until the button is released.
3. Once the button is released, I want the box to decelerate from 5 pixels to 0 pixels.

I am familiar with the p(t) = t \* v equations, but I am unsure how to implement it in this particular fashion. If anyone has any tips or clues, I’d greatly appreciate it! Thanks.

====

box.\_x = 0;

go.onPress = function() {  
// 1. make box accelerate from 0 to 5 pixels per frame to the right  
// 2. once the box is up to speed at 5 pixels per frame, hold the rate of movement at 5 pixels per frame.  
}

go.onRelease = function() {  
// 1. decelerate motion from 5 to 0 pixels per frame, until the box stops moving  
}
