# \[F5\] Charicter Movment L/R with animation

**URL:** <https://forum.kirupa.com/t/f5-charicter-movment-l-r-with-animation/8866>\
**Category:** flash\
**Created:** [November 29, 2002, 9:11pm UTC](https://forum.kirupa.com/t/f5-charicter-movment-l-r-with-animation/8866 "2002-11-29T21:11:17Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![MekiDent](https://avatars.discourse-cdn.com/v4/letter/m/f6c823/32.png) [@MekiDent](https://forum.kirupa.com/u/MekiDent)\
**Post date:** [November 29, 2002, 9:11pm UTC](https://forum.kirupa.com/t/f5-charicter-movment-l-r-with-animation/8866/1 "2002-11-29T21:11:17Z")

</div>

So what i want is:  
i have a charicter, and when the left key is pressed the charicter moves left while playing a Movie clip of the charicter walking stored in the library. once that is done the charicter stays pointed in that direction unil it is pointed right by the right key. going up of down does not need any special animations and i can already keep the charicter on the screen

here is a sample of the code for moving left

```auto

if (Key.getCode() == Key.LEFT) {
       //plays mcwalkL
       gotoAndPlay(_root.mcwalkL);
	//Stops player from exiting the screen
	if (this._x > MIN_X){
	this._x = this._x - 15;
//facing sets the charicter in same direction they walked
	facing = 2;
	}

} if (facing = 2){
      gotoAndPlay(_root.mcstandL);

```

MIN\_X is the edge of the sceen  
mcstand - is the object with the coding every clip of mc (main charicter) is either pointed right. facing=1, or left, facing = 2 containing a L after it

the coding for right movment if staments is identical only without the L

when playing this. i can move the charicter around the screen keeping them in the area i need it. But the animation does not play so i have a standing guy floating around

So what am i doing 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:** [November 30, 2002, 5:49am UTC](https://forum.kirupa.com/t/f5-charicter-movment-l-r-with-animation/8866/2 "2002-11-30T05:49:29Z")

</div>

bump

---

<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:** [November 30, 2002, 5:52am UTC](https://forum.kirupa.com/t/f5-charicter-movment-l-r-with-animation/8866/3 "2002-11-30T05:52:32Z")

</div>

I have done something like this in MX, but the process I used can’t be done in 5, so I don’t know how to do it here

☹

---

<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 1, 2002, 2:24pm UTC](https://forum.kirupa.com/t/f5-charicter-movment-l-r-with-animation/8866/4 "2002-12-01T14:24:39Z")

</div>

if (facing == 2) for a start 🙂

---

<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 1, 2002, 7:58pm UTC](https://forum.kirupa.com/t/f5-charicter-movment-l-r-with-animation/8866/5 "2002-12-01T19:58:04Z")

</div>

the problem is the gotoAndPlay(\_root.mcwalkL); does not work i need a comand that does

---

<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 1, 2002, 7:59pm UTC](https://forum.kirupa.com/t/f5-charicter-movment-l-r-with-animation/8866/6 "2002-12-01T19:59:43Z")

</div>

What Ilyas said.

= is making a value equal something

== is checking to make sure a value equals something.

so in this case you want

if (facing == 2){  
gotoAndPlay(\_root.mcstandL);  
}

Iam checking the code to see why the walkleft thing isn’t working.

---

<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 1, 2002, 8:15pm UTC](https://forum.kirupa.com/t/f5-charicter-movment-l-r-with-animation/8866/7 "2002-12-01T20:15:04Z")

</div>

Ok, I believe you have to add a listener to find out what key was pressed.

I am not sure if this works in Flash 5 since I don’t use it, but you can try this…

```auto
//define listener object
keyListener = new Object();
//create function for when a key is pressed
keyListener.onKeyDown = function() {
	keypressed = Key.getCode();
	//if Key.getCode == Key.LEFT
	if (keypressed == Key.LEFT) {
		//plays mcwalkL
		gotoAndPlay(_root.mcwalkL);
		//Stops player from exiting the screen
		if (this._x>MIN_X) {
			this._x = this._x-15;
			//facing sets the charicter in same direction they walked
			facing = 2;
		}
	}
	if (facing == 2) {
		gotoAndPlay(_root.mcstandL);
	}
};
//adds listener to see if key was pressed
Key.addListener(keyListener);

```

---

<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 1, 2002, 8:17pm UTC](https://forum.kirupa.com/t/f5-charicter-movment-l-r-with-animation/8866/8 "2002-12-01T20:17:45Z")

</div>

Ok thanks

im more concerned about the gotoAndPlay because it is in all the instances when the charicter moves. and it does not work.  
The item is stored in a library and if there is another function that would work for that it would be helpful  
Right now im guessing I used the gotoAndPlay function wrongly

---

<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 1, 2002, 8:22pm UTC](https://forum.kirupa.com/t/f5-charicter-movment-l-r-with-animation/8866/9 "2002-12-01T20:22:24Z")

</div>

I probably posted while you were replying, so just in case… look above at my last post 🙂

---

<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 1, 2002, 8:33pm UTC](https://forum.kirupa.com/t/f5-charicter-movment-l-r-with-animation/8866/10 "2002-12-01T20:33:48Z")

</div>

thank you lostinbeta ,but that does not seem to work in flash 5 i plugged that in for walking left and i couldnt make the charicter walk that way. What does a listener do? i am able to have the charicter move but not play the animation

---

<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 1, 2002, 8:36pm UTC](https://forum.kirupa.com/t/f5-charicter-movment-l-r-with-animation/8866/11 "2002-12-01T20:36:32Z")

</div>

Yeah, I just looked up about listeners, they are MX Specific ☹

I am still working on finding a Flash 5 way though 🙂

---

<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 1, 2002, 8:42pm UTC](https://forum.kirupa.com/t/f5-charicter-movment-l-r-with-animation/8866/12 "2002-12-01T20:42:10Z")

</div>

Ok, again… still not sure but try this…

```auto
onClipEvent (enterFrame) {
	if (Key.isDown(Key.LEFT)) {
		//plays mcwalkL
		gotoAndPlay(_root.mcwalkL);
		//Stops player from exiting the screen
		if (this._x>MIN_X) {
			this._x -= 15;
			//facing sets the charicter in same direction they walked
			facing = 2;
		}
	}
	if (facing == 2) {
		gotoAndPlay(_root.mcstandL);
	}
}

```

I also changed this.\_x = this.\_x-15; to this.\_x -= 15; it does the same thing, but is much easier 🙂

---

<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 1, 2002, 9:46pm UTC](https://forum.kirupa.com/t/f5-charicter-movment-l-r-with-animation/8866/13 "2002-12-01T21:46:34Z")

</div>

ok that does work but the animation still does not play but i did like the  
this.\_x -= 15;  
Is there one for moving right?  
I used

this.\_x += 15;  
but it did not work

---

<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 1, 2002, 9:49pm UTC](https://forum.kirupa.com/t/f5-charicter-movment-l-r-with-animation/8866/14 "2002-12-01T21:49:05Z")

</div>

this.\_x +=15 should make it go right.

gotoAndPlay(\_root.mcwalkL);

Should be \_root.mcwalkL.gotoAndPlay(frame#)

Sorry, I meant to correct that last time

---

<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 1, 2002, 10:00pm UTC](https://forum.kirupa.com/t/f5-charicter-movment-l-r-with-animation/8866/15 "2002-12-01T22:00:17Z")

</div>

Im sorry i did not change the code for right in the keydown += does work but the problem is it is not in a frame it is saved as a movie clip in my library so

\_root.mcwalkL.gotoAndPlay(frame#)

would not work is there another fuction that would work with stored movie clips

Thank you for all this 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 1, 2002, 10:02pm UTC](https://forum.kirupa.com/t/f5-charicter-movment-l-r-with-animation/8866/16 "2002-12-01T22:02:25Z")

</div>

Nope, no other way to goto and play a frame in a movie clip other than gotoAndPlay.

You did replace the frame# part with the frame # you wish to be played right?

And if it is a frame label, it must be encased in " " (double quotes)

Can you post a .fla file???

---

<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 2, 2002, 6:58pm UTC](https://forum.kirupa.com/t/f5-charicter-movment-l-r-with-animation/8866/17 "2002-12-02T18:58:56Z")

</div>

the gotoAndPlay operation is not what i needed in this code so i went for the attachMovie operation; however only the mcwalk2 animaiton plays and the charicter cannot move here is what i got so far

```auto

if (Key.isDown(Key.LEFT)) {
	// clears the previous animation
	// plays the correct animation
	attachMovie("mcwalk2", "mc", 1);
	// facing keeps charicter in right direction when no buttons are pressed
               // clears the previous animation
	removeMovieClip ("mc");
	facing = 2;
	if (mc._x>MIN_X) {
		mc._x -= 15;
	}
if (facing == 1) {
	attachMovie("mcstand1", "mc", 1);

```

i typed this into a layer that spans the whole movie and i can keep the background the same.  
also when is it better to use duplicateMovie operation?

---

<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 3, 2002, 7:11am UTC](https://forum.kirupa.com/t/f5-charicter-movment-l-r-with-animation/8866/18 "2002-12-03T07:11:38Z")

</div>

Well, I am not 100% on this, but I believe for what you are trying to do, it would only work if your if actions are on your movie clip in an onClipEvent (enterFrame) handler.

When is it better to use duplicateMovieClip for what or instead of what?

::this would be a lot easier to solve if I had flash 5 :-\ :(::

Anyone else reading this have Flash 5 that can help?
