PDA

View Full Version : small problem with key bindings.


omega10mg
08-26-2003, 10:06 AM
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
this.gotoAndPlay(10);
}
if (Key.isDown(Key.LEFT)) {
this.gotoAndPlay(6);
}
if (Key.isDown(Key.RIGHT)) {
this.gotoAndPlay(2);
}
Key.A = 65;
if (Key.isDown(Key.A)) {
this._x -= 5;
}
Key.S = 83;
if (Key.isDown(Key.S)) {
this._x += 5;
}
}

thats my script as it is now. and it works =)

my question is, how can i make only the left, right and up keys work if I am not pressing A or S at the same time. you unedrstand.
You should only be able to do one action at the time. and when u release one key u can press another. how?

lochwinnoch
08-26-2003, 07:52 PM
A variable stating if ANY KEY is being pressed will do this.


onClipEvent (load) {
keyPressed = false;
}

onClipEvent (enterFrame) {
if (!keyPressed) {
if (Key.isDown(Key.UP)) {
this.gotoAndPlay(10);
keyPressed = Key.UP;
}
if (Key.isDown(Key.LEFT)) {
this.gotoAndPlay(6);
keyPressed = Key.LEFT;
}
if (Key.isDown(Key.RIGHT)) {
this.gotoAndPlay(2);
keyPressed = Key.RIGHT;
}
Key.A = 65;
if (Key.isDown(Key.A)) {
this._x -= 5;
keyPressed = Key.A;
}
Key.S = 83;
if (Key.isDown(Key.S)) {
this._x += 5;
keyPressed = Key.S;
}
}
if (!Key.isDown(keyPressed)) {
keyPressed= false;
}
}

omega10mg
08-26-2003, 08:28 PM
thank you! very nice!
worked perfect =)