# Movement

**URL:** <https://forum.kirupa.com/t/movement/38311>\
**Category:** Uncategorized\
**Created:** [December 21, 2003, 2:37am UTC](https://forum.kirupa.com/t/movement/38311 "2003-12-21T02:37:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Comglomo](https://avatars.discourse-cdn.com/v4/letter/c/e19adc/32.png) [@Comglomo](https://forum.kirupa.com/u/Comglomo)\
**Post date:** [December 21, 2003, 2:37am UTC](https://forum.kirupa.com/t/movement/38311/1 "2003-12-21T02:37:53Z")

</div>

Ok… I have a simple code for movement…

```auto

on (keyPress "<Left>") {
	currentX = this._x;
	this._x = currentX - 2;
	_root.hansl_front._rotation = 270;
}
on (keyPress "<Right>") {
	currentX = this._x;
	this._x = currentX + 2;
	_root.hansl_front._rotation = 90;
}
on (keyPress "<Up>") {
	currentY = this._y;
	this._y = currentY - 2;
	_root.hansl_front._rotation = 360;
}
on (keyPress "<Down>") {
	currentY = this._y;
	this._y = currentY + 2;
	_root.hansl_front._rotation = 180;
}

```

I want it so that whenever you hit like the up button… it changes the movieclip to a differnt image so it looks like the character is actually walking forward backwards and ect…  
thanks for your help

---

<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:** [December 21, 2003, 2:43am UTC](https://forum.kirupa.com/t/movement/38311/2 "2003-12-21T02:43:28Z")

</div>

if you add another keyframe to your character mc…  
put a stop on the first frame, then add something like this to your code:

[AS]  
on (keyPress “\<Left\>”) {  
currentX = this.\_x;  
this.\_x = currentX - 2;  
\_root.hansl\_front.\_rotation = 270;  
\_root.hansl\_front.gotoAndPlay(2);  
}  
[/AS]

---

<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:** [December 21, 2003, 2:52am UTC](https://forum.kirupa.com/t/movement/38311/3 "2003-12-21T02:52:59Z")

</div>

hmm that doesnt work… he still just walks up if i edit it to this

```auto

on (keyPress "<Up>") {
        currentX = this._y;
        this._y = currentX - 2;
        _root.hansl_front._rotation = 270;
        _root.hansl_front.gotoAndPlay(2);

}

```

?

---

<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:** [December 21, 2003, 4:00pm UTC](https://forum.kirupa.com/t/movement/38311/4 "2003-12-21T16:00:29Z")

</div>

Any Ideas?

---

<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:** [December 21, 2003, 4:13pm UTC](https://forum.kirupa.com/t/movement/38311/5 "2003-12-21T16:13:43Z")

</div>

thats the way its done :-\

---

<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:** [December 21, 2003, 4:22pm UTC](https://forum.kirupa.com/t/movement/38311/6 "2003-12-21T16:22:55Z")

</div>

wait… do i have to have the other image inside of the movie clip? like when you go to edit your movie clip… you put your new image in there?

---

<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:** [December 21, 2003, 4:26pm UTC](https://forum.kirupa.com/t/movement/38311/7 "2003-12-21T16:26:58Z")

</div>

yes. Instead of your movieclip being one static image, have it 2 frames. One of standing (frame 1), and one of walking (frame 2). Put a stop() on frame 1 so it starts standing. Then when the character moves, go to frame 2 so its walking. OF course with you’re current setup, moving on keypress like that, it might not work so well since you have no way to detect a return to the standing position - not easily at least. You might want to search the forums for movement with keys and look at alternative approaches (i.e. using 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:** [December 21, 2003, 8:54pm UTC](https://forum.kirupa.com/t/movement/38311/8 "2003-12-21T20:54:08Z")

</div>

man i cant get this…

I have my movie clip on my regular layer… he has his actions… when I edit him he has two keyframes… one of him standing there and that action has  
stop(); and right next to it is the other part of him so that it looks like hes actually walking… when I go to preview the scene it just makes him move upwards without changing the picture… ☹  
character standing regular actionscript

```auto

on (keyPress "<Left>") {
        currentX = this._x;
        this._x = currentX - 2;
        _root.hansl_front._rotation = 270;
}

on (keyPress "<Right>") {
	currentX = this._x;
	this._x = currentX + 2;
	_root.hansl_front._rotation = 90;
}
on (keyPress "<Up>") {
        currentY = this._y;
        this._y = currentX - 2;
        _root.hansl_front.gotoAndPlay(2);

}

on (keyPress "<Down>") {
	currentY = this._y;
	this._y = currentY + 2;
	_root.hansl_front._rotation = 180;
}

```
