# Moving function

**URL:** <https://forum.kirupa.com/t/moving-function/151901>\
**Category:** flash\
**Created:** [June 19, 2005, 11:28am UTC](https://forum.kirupa.com/t/moving-function/151901 "2005-06-19T11:28:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dboers](https://avatars.discourse-cdn.com/v4/letter/d/bbe5ce/32.png) [@dboers](https://forum.kirupa.com/u/dboers)\
**Post date:** [June 19, 2005, 11:28am UTC](https://forum.kirupa.com/t/moving-function/151901/1 "2005-06-19T11:28:40Z")

</div>

I use the following function to move a mc to a certain y position. When that y position is reached the mc goes back to it’s original position:

```auto
 
function moveInOut (clip, yPos, speed){
	var yStart = clip._y ;
	var yTarget = yPos;
	clip.onEnterFrame = function (){
		var dY= yTarget - this._y;
		this._y += dY / speed;
		if (Math.abs(dY) < 2){
			if (yTarget == yPos) {
				yTarget = yStart ;
			}
			else {
				this._y = yStart;
				delete this.onEnterFrame;
			}
		} 
	};
} ;

```

and on the button:

```auto
on (release) {
moveInOut (menu, 200, 10)
}

```

But I don’t want the mc going back to it’s original position but to a completely different y position to create kind of a bounce effect

Has anybody an idea how to accomplish that?

Thanks in advance
