# Movement code

**URL:** <https://forum.kirupa.com/t/movement-code/111224>\
**Category:** Uncategorized\
**Created:** [May 24, 2004, 11:25pm UTC](https://forum.kirupa.com/t/movement-code/111224 "2004-05-24T23:25:33Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vexir](https://avatars.discourse-cdn.com/v4/letter/v/a183cd/32.png) [@Vexir](https://forum.kirupa.com/u/Vexir)\
**Post date:** [May 24, 2004, 11:25pm UTC](https://forum.kirupa.com/t/movement-code/111224/1 "2004-05-24T23:25:33Z")

</div>

i put this code into a button…

```auto
on (release) {
	if (_root.menu._x != 298.7) {
		speed = 1;
		_root.menu._x += speed;
    } else {
		stop();
	}
}

```

but it only increments its \_x by 1 when i repeatedly click it… shouldn’t it continue to run through the loop?

---

<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:** [May 24, 2004, 11:26pm UTC](https://forum.kirupa.com/t/movement-code/111224/2 "2004-05-24T23:26:20Z")

</div>

or do i need a for loop?

---

<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:** [May 24, 2004, 11:36pm UTC](https://forum.kirupa.com/t/movement-code/111224/3 "2004-05-24T23:36:51Z")

</div>

You have it on an on release which means that it runs through the code once with each click. So yes you need a for loop or maybe try one of the easing equations out there?

:hr:

---

<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:** [May 24, 2004, 11:38pm UTC](https://forum.kirupa.com/t/movement-code/111224/4 "2004-05-24T23:38:04Z")

</div>

I did something similar, but for a movieclip. Put this code into a movieclip, and tell me if that is something like you want.

```auto
onClipEvent (load) {
	_x = 18;
	div = 5;
}
onClipEvent (enterFrame) {
	_x += (endX-_x)/div;
	_root.link_mc.onPress = function() {
		endX = 40;
	};
	_root.link_mc.onRelease = function() {
		endX = 18;
	};
}

```

---

<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:** [May 25, 2004, 12:14am UTC](https://forum.kirupa.com/t/movement-code/111224/5 "2004-05-25T00:14:24Z")

</div>

i didnt even bother, there were too many errors in it when flash tried to do that… anyway, can someone tell me how to do a for loop to make that work?  
i tried:

```auto

on (release) {
     for (_root.menu._x != 298.7; _root.menu._x != 298.7; ) {
		speed = 3;
	    _root.menu._x += speed;
     }
}

```

but that came up with something about it being too processor intensive that it will hang my system

---

<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:** [May 26, 2004, 2:29am UTC](https://forum.kirupa.com/t/movement-code/111224/6 "2004-05-26T02:29:38Z")

</div>

im confused… btw lunatic, those scripts didnt work… when i clicked it, nothing happened… and i put the first script on a separate actions layer in frame one, and then i put the second on the button…

---

<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:** [May 27, 2004, 3:03pm UTC](https://forum.kirupa.com/t/movement-code/111224/7 "2004-05-27T15:03:47Z")

</div>

Let’s say your button’s instance name is ‘but’, put this in the main timeline

```auto
speed = 3 ;

but.onRelease = function () {
     _root.menu.move () ;
} ;

function move () {
     this.onEnterFrame = function () {
          this._x += speed ;
          if (this._x < 300 && this._x > 295) delete this.onEnterFrame ;
     } ;
} ;

```

---

<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:** [May 27, 2004, 10:02pm UTC](https://forum.kirupa.com/t/movement-code/111224/8 "2004-05-27T22:02:20Z")

</div>

> put this in the main timeline

like, on a separate actions layer in frame one?

---

<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:** [May 28, 2004, 2:22pm UTC](https://forum.kirupa.com/t/movement-code/111224/9 "2004-05-28T14:22:02Z")

</div>

Yes.

---

<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:** [May 29, 2004, 3:27pm UTC](https://forum.kirupa.com/t/movement-code/111224/10 "2004-05-29T15:27:24Z")

</div>

still didnt work, :-/ check it out… (I couldnt attach the FLA it was about 700 kb too big :moustache )

---

<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:** [May 29, 2004, 3:28pm UTC](https://forum.kirupa.com/t/movement-code/111224/11 "2004-05-29T15:28:28Z")

</div>

K here is the .fla:

[http://www.graphicslash.com/mathprojectworking.fla](http://www.graphicslash.com/mathprojectworking.fla)

---

<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:** [May 29, 2004, 3:45pm UTC](https://forum.kirupa.com/t/movement-code/111224/12 "2004-05-29T15:45:09Z")

</div>

I implemented the code you guys have been talking about in this thread…it’s in the first frame, GS.

[http://digitalink-designs.com/gs.zip](http://digitalink-designs.com/gs.zip)

Adam

---

<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:** [May 29, 2004, 6:04pm UTC](https://forum.kirupa.com/t/movement-code/111224/13 "2004-05-29T18:04:37Z")

</div>

heey thanks adam, i wonder what i did wrong ☹

---

<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:** [May 29, 2004, 10:19pm UTC](https://forum.kirupa.com/t/movement-code/111224/14 "2004-05-29T22:19:45Z")

</div>

My mistake.

```auto
speed = 3 ;

but.onRelease = function () {
     _root.menu.move () ;
} ;

MovieClip.prototype.move = function () {
     this.onEnterFrame = function () {
          this._x += speed ;
          if (this._x < 300 && this._x > 295) delete this.onEnterFrame ;
     } ;
} ;

```

Is this working any better?

---

<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:** [May 30, 2004, 2:10am UTC](https://forum.kirupa.com/t/movement-code/111224/15 "2004-05-30T02:10:17Z")

</div>

yes thanks 🙂
