PDA

View Full Version : Controlling a Walking Person


murphysuk
01-31-2009, 09:49 PM
I have created a movie clip of 5 frames:

1 Stand still
2 Walk Left
3 Stop Left (with stop() action)
4 Walk Right
5 Stop Right (with stop() action)

I have written script so that the Left arrow moves the movie clip to frame 2 and the movie clip moves left. The right arrow moves to frame 4 and does the opposite.

My aim is for frames 2 and 4 to move onto the next frame when the arrow key is released.

Sometimes it does and sometimes it doesn't!! Is there anyway to ensure that the movies clip moves onto the standing left (or right) frame.

Many thanks,

Steven.

murphysuk
02-01-2009, 10:43 AM
I have found a thread (which I have subsequently lost) that outlines a very similar problem and gives a partial solution.

The script used is as follows:

onClipEvent (enterFrame) {
a=2
b=0
onEnterFrame=function(){
if (Key.isDown(Key.RIGHT)) {
this._x = this._x+10;
gotoAndStop(4);
a = 1;
b = 0;
}
if (!Key.isDown(Key.RIGHT)) {
if (a<>0) {
a = 2;
}
if (a == 2) {
gotoAndStop(5);
}
}
if (Key.isDown(Key.LEFT)) {
this._x = this._x-10;
gotoAndStop(2);
b = 1;
a = 0;
}
if (!Key.isDown(Key.LEFT)) {
if (b<>0) {
b = 2;
}
if (b == 2) {
a = 2;
gotoAndStop(3);
}
}
}}

This script allows the character to "walk right" and, when the key is released, "look right". However, when the character "walks left" it then "looks right" when the key is released. I don't understand why it doesn't move to frame 3 (gotoAnd Stop(3)) but still goes to frame 5.

Again many thanks for any help.

Steven.