# Seamingly easy movement?

**URL:** https://forum.kirupa.com/t/seamingly-easy-movement/57761
**Category:** Uncategorized
**Created:** [July 15, 2004, 11:16pm UTC](https://forum.kirupa.com/t/seamingly-easy-movement/57761 "2004-07-15T23:16:04Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![johnnyFlash](https://avatars.discourse-cdn.com/v4/letter/j/2bfe46/32.png) [@johnnyFlash](https://forum.kirupa.com/u/johnnyFlash)
#### Post date: [July 15, 2004, 11:16pm UTC](https://forum.kirupa.com/t/seamingly-easy-movement/57761/1 "2004-07-15T23:16:04Z")

</div>

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

```auto

 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

---

<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: [July 16, 2004, 12:03am UTC](https://forum.kirupa.com/t/seamingly-easy-movement/57761/2 "2004-07-16T00:03:23Z")

</div>

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.

```auto

////////////////////////////////////////////////////////////////////////////////////////////////////
 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
 

```

---

<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: [July 16, 2004, 12:07am UTC](https://forum.kirupa.com/t/seamingly-easy-movement/57761/3 "2004-07-16T00:07:48Z")

</div>

[http://www.macromedia.com/support/flash/action\_scripts/actionscript\_dictionary/](http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/)

---

<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: [July 16, 2004, 12:07am UTC](https://forum.kirupa.com/t/seamingly-easy-movement/57761/4 "2004-07-16T00:07:59Z")

</div>

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 🙂

---

<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: [July 16, 2004, 6:55am UTC](https://forum.kirupa.com/t/seamingly-easy-movement/57761/5 "2004-07-16T06:55:24Z")

</div>

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

```

In your code

```auto
 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(-:

---

<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: [July 16, 2004, 8:19am UTC](https://forum.kirupa.com/t/seamingly-easy-movement/57761/6 "2004-07-16T08:19:30Z")

</div>

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

---

<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: [July 16, 2004, 8:23am UTC](https://forum.kirupa.com/t/seamingly-easy-movement/57761/7 "2004-07-16T08:23:09Z")

</div>

> 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 🙂

---

<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: [July 16, 2004, 5:31pm UTC](https://forum.kirupa.com/t/seamingly-easy-movement/57761/8 "2004-07-16T17:31:30Z")

</div>

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

---

<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: [July 17, 2004, 3:09am UTC](https://forum.kirupa.com/t/seamingly-easy-movement/57761/9 "2004-07-17T03:09:18Z")

</div>

Hi again, this is working fine and i understand it a lot better (especially i learned about the whole \<= 🙂 ) 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.

```auto

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

```

I hope i can get some help :thumb:

---

<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: [July 17, 2004, 7:31am UTC](https://forum.kirupa.com/t/seamingly-easy-movement/57761/10 "2004-07-17T07:31:58Z")

</div>

Like this?

```auto
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(-:
