# MoveTo Function

**URL:** <https://forum.kirupa.com/t/moveto-function/209115>\
**Category:** flash\
**Created:** [December 6, 2006, 12:38am UTC](https://forum.kirupa.com/t/moveto-function/209115 "2006-12-06T00:38:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jor133d](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/jor133d/32/315_2.png) [@jor133d](https://forum.kirupa.com/u/jor133d)\
**Post date:** [December 6, 2006, 12:38am UTC](https://forum.kirupa.com/t/moveto-function/209115/1 "2006-12-06T00:38:17Z")

</div>

Hello,

I am working on a simple eportfolio for one of my college classes. I am trying to made one movieclip (instance: main) move horizontally when you click on buttons. I have two buttons one of the left side of the the stage (Instance: show) that slides “main” to the right; and one of the right side of the stage (instace: hide) that slides “main” to the left.

Problem:

According to my script now, I can only move the movie once to a defines x-value. How can I get it so when the button is clicked it continues to move “main” multiple times?

Code:

```auto

function MoveTo (clip, fadeType, xTo, yTo, speed) {
	clip.onEnterFrame = function () {
		this._x += (xTo -this._x) * speed;
		this._y += (yTo - this._y) * speed;
		if (fadeType == "in" && this._alpha <100){
			this._alpha += 5;
		}else if (fadeType == "out" && this._alpha >0) {
			this.alpha -=5;
		}
	};
}

show.onPress = function () {
	MoveTo (main, "in", 160, 40, 0.3);
};

hide.onPress = function () {
	MoveTo (main, "out", -450, 40, 0.3);
};

```
