# Whats the problem?

**URL:** <https://forum.kirupa.com/t/whats-the-problem/34148>\
**Category:** Uncategorized\
**Created:** [October 28, 2003, 8:07pm UTC](https://forum.kirupa.com/t/whats-the-problem/34148 "2003-10-28T20:07:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yazzman](https://avatars.discourse-cdn.com/v4/letter/y/58956e/32.png) [@yazzman](https://forum.kirupa.com/u/yazzman)\
**Post date:** [October 28, 2003, 8:07pm UTC](https://forum.kirupa.com/t/whats-the-problem/34148/1 "2003-10-28T20:07:05Z")

</div>

Hi

Im trying to get this an object to go from position A to B and back, in infinity!!I only get the object to go from A to be B and then it stops. The code is in the MovieClip actions.

Here is the code…

onClipEvent (enterFrame) {

this.onEnterFrame=goRight;  
goRight=function()  
{  
if (this.\_y\<250) this.\_y+=1;  
else this.goLeft;  
}  
goLeft=function()  
{  
if (this.\_y\>50) this.\_y-=1;  
else this.goRight;  
}  
}

:mario:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 29, 2003, 11:31am UTC](https://forum.kirupa.com/t/whats-the-problem/34148/2 "2003-10-29T11:31:26Z")

</div>

Hi,

> 

if (this.\_y\<250) this.\_y+=1;  
else this.goLeft;  
}

your clip’s \_y is always less than 250!!!  
you need to know when is going down and when is going up:

[AS]  
onClipEvent (load) {  
this.direction = “down”;  
}  
onClipEvent (enterFrame) {  
if(this.direction == “down”){  
if (this.\_y\<250){  
this.\_y+=1;  
} else{  
this.direction = “up”;  
}  
} else if(this.direction == “up”){  
if (this.\_y\>50){  
this.\_y-=1;  
}else {  
this.direction = “down”;  
}  
}  
}

[/AS]

SHO

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 29, 2003, 1:10pm UTC](https://forum.kirupa.com/t/whats-the-problem/34148/3 "2003-10-29T13:10:30Z")

</div>

Or this:

```auto

onClipEvent (load) {
	direction = 1;
	speed = 3;
	xlimit = {l:0, r:700};
	_x = xlimit.l+_width/2
}
onClipEvent (enterFrame) {
	_x += direction*speed;
	if (_x+_width/2>xlimit.r) {
		_x = xlimit.r;
		direction *= -1;
	}
	if (_x-_width/2<xlimit.l) {
		_x = xlimit.l;
		direction *= -1;
	}
}

```
