[F5] Charicter Movment L/R with animation

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


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?

bump

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

:frowning:

if (facing == 2) for a start :slight_smile:

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

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.

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…

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

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

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

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

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

I am still working on finding a Flash 5 way though :slight_smile:

Ok, again… still not sure but try this…

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 :slight_smile:

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

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

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

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

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


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?

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?