PDA

View Full Version : [MX] 2 keys



Tomoko_Sasaki
March 4th, 2003, 08:54 AM
in actionscript, Is there a way i can make a coddition happen if 2 keys at once are presssed?

example:
if (Key.isDown(Key.SHIFT) && (Key.isDown(Key.LEFT) && _currentframe == 1)) {
gotoAndPlay("running_left");
} else if (Key.isDown(Key.RIGHT) && (Key.isDown(Key.RIGHT) && _currentframe == 1)) {
gotoAndPlay("running_right");
}

or can't i do shift and left/right?

michelle

Lunar_4u
March 4th, 2003, 09:35 AM
I had a go at what you were trying to achieve and came up with this code that seemed to work...

onClipEvent (enterFrame) {
if ((Key.isDown(Key.SHIFT)) and (Key.isDown (Key.LEFT))) {
this.gotoAndStop("running_left");
} else if ((Key.isDown(Key.SHIFT)) and (Key.isDown(Key.RIGHT))) {
this.gotoAndStop("running_right");
}
}

You put that code on the actaul moveclip that i assume you are trying to animate (-:

CyanBlue
March 4th, 2003, 11:01 PM
Another option by using the Key listener...
This won't take more CPU power than onEnterFrame handler...

keyDetector = new Object();
keyDetector.onKeyDown = function()
{
if ((Key.isDown(Key.SHIFT)) && (Key.isDown(Key.LEFT)))
{
yourMC.gotoAndStop("running_left");
trace("running_left");
}
else if ((Key.isDown(Key.SHIFT)) && (Key.isDown(Key.RIGHT)))
{
yourMC.gotoAndStop("running_right");
trace("running_right");
}
};
Key.addListener(keyDetector);Please use code formatting (http://www.kirupaforum.com/misc.php?action=bbcode#buttons) next time when you post the code... ;)