Whats the problem?

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:

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

Or this:


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;
	}
}