Seamingly easy movement?

I have a block that i’m trying to make move from right to left, and if the block gets to a certain point, it will move back to it’s original position.
So, i have this on my block (movieclip) rightnow


 onClipEvent(enterFrame) {
 	speed = 3
 	dist = 8.5
 	_x -= speed;
 	if (_x = dist) {
 		_x += 3
 	}
 }
 

But all this is doing is throwing the block at the 8.5 distance…

any help??? Thanx in advance

I once wrote a [color=Magenta]prototype [/color]that I use for moving stuff around. Maybe this is a little more than you need, but you can sort out the things you want to use. About your code above, I think you should define speed and dist ONCE, not on every frame. And, don’t forget the difference between = and ==. Ask me if you have any questions.


////////////////////////////////////////////////////////////////////////////////////////////////////
 MovieClip.prototype.Animate = function(steps,newX,newY) {
  this.onEnterFrame = function() {
	difX = Math.round(newX-this._x);
	difY = Math.round(newY-this._y);
	if ( difX != 0 or difY != 0) {
	  this._x += difX/steps;
	  this._y += difY/steps;
	} else {
	  delete this.onEnterFrame;
	  // This will happen when animation is complete
	  this.Animate(3,200,0);
	}
  }
 }
 
 my_mc.Animate(3,15,60); // steps,newX, newY
 

http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/

Hm, your way is a little complex for me…as i am just beginnning to work with AS…Does my way not work at all after a little tweaking? Or should i just tough it out and read through some tutorials regarding your method?

THANKS a lot :slight_smile:

onClipEvent (load) {
	speed = 3;
	dist = 8.5;
	origX = _x;
}
onClipEvent (enterFrame) {
	_x -= speed;
	if (_x <= dist) {
		_x = origX;
	}
}

In your code

 if (_x = dist) {

the value of dist is assigned to _x, not compared, use "=="instead:)
I’ve used “<=” cause _x probably never gets equal to “dist” (depends on your setup)

scotty(-:

Hi, I’m trying to do something along the same lines as johnnyFlash… I have an image that I’m trying to get to scroll up until it gets to a certain point, then I want it to stop. How do I do this? I’m using:

onClipEvent(enterFrame) {
speed = 1;
this._y += speed;
}

Thanks

Hi, I’m trying to do something along the same lines as johnnyFlash… I have an image that I’m trying to get to scroll up until it gets to a certain point, then I want it to stop. How do I do this? I’m using:

onClipEvent(enterFrame) {
speed = 1;
this._y += speed;
}

Thanks

onClipEvent(enterFrame) {
if(certainPoint > this._y) {
speed = 1;
this._y += speed;
}
}

Hope that helps :slight_smile:

Actually that’s a scroll down, but whatever! Remember that the _y is “upside down” in flash, thus the higher you are, the less is _y. The more down you go, the greater is _y.

So, ulysnep, if you want your movieclip to scroll UP, you’re gonna have to use negative speed ( or this._y-= speed instead of += ) and you’ll also have to make sure that your if conditionnal is appropriate, something along the lines of:
if(this._y> stopPosition){
this._y-=speed;
//OR, if speed is a negative variable:
this._y+=speed;
}

Hi again, this is working fine and i understand it a lot better (especially i learned about the whole <= :slight_smile: ) But, what i kind of wanted to do was send the block back to it’s original point by moving, not just jumping right over there. So i was thinking something like this may give you an idea of what i’m talking about.


 onClipEvent (load) {
 	speed = 3;
 	dist = 8.5;
 }
 onClipEvent (enterFrame) {
 	_x -= speed;
 	if (_x <= dist) {
 		_x += 3;
 	}
 }
 

I hope i can get some help :thumb:

Like this?

onClipEvent (load) {
	speed = 3;
	dist = 8.5;
	xMax = 400;
}
onClipEvent (enterFrame) {
	_x -= speed;
	if (_x<=dist) {
		speed = -speed;
	} else if (_x>=xMax) {
		speed = -speed;
	}
}

change xMax to the value you want:)

scotty(-: