all groups > flash actionscript > february 2006 >
You're in the

flash actionscript

group:

How can you make a mc move left when you hit the A key


Re: How can you make a mc move left when you hit the A key mostlyliquid
2/21/2006 2:50:51 PM
flash actionscript:
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
if(Key.getCode() == 65) { //65 is an A
trace("It's an A!");
}
trace("DOWN -> Code: "+Key.getCode()+"\tACSII:
"+Key.getAscii()+"\tKey: "+chr(Key.getAscii()));

};
Key.addListener(keyListener);

I left that second trace in there - any key you press will trace its
code. Look in your output window when you publish in flash, it will
show the traces. Thats pretty much straight from flash help - search
for Key.onKeyDown for more and related info. HTH!

-J
Re: How can you make a mc move left when you hit the A key -->dan mode
2/21/2006 4:59:19 PM
I've got a sample fla posted here:
http://www.smithmediafusion.com/blog/?p=52

--

Dan Mode
*Must Read* http://www.smithmediafusion.com/blog
*Flash Helps* http://www.smithmediafusion.com/blog/?cat=11

[quoted text, click to view]

How can you make a mc move left when you hit the A key rbr1234
2/21/2006 9:08:48 PM
im want to know how to make and object move left when i hit the A key

i know how to do it with the arrow keys but not the Letter Keys

Can you tell me and make and exaple


Sincerly,
Re: How can you make a mc move left when you hit the A key blemmo
2/21/2006 10:51:31 PM
You can use this to get the Keycode for any pressed button:
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
trace("The Key code is: "+Key.getCode());
};
Key.addListener(keyListener);

For the A key, this returns 65, so you can use
if (Key.getCode() == 65) { //move left }
in your KeyListener.

greets,
blemmo
Re: How can you make a mc move left when you hit the A key bhnh
2/22/2006 12:15:58 AM
Appendex C of the ActionScript 2.0 Dictionary lists the ACSII key code values
for all the keys on the keyboard. If you were using the Left Arrow key you'd
write:

if(Key.isDown(Key.LEFT)) {
someClip._x -= someNumber;
}

The ASCII code for "A" is 65, so to perform the same action with the "A" key
you'd write:

If(Key.isDown(65)) {
someClip._x -= someNumber;
}
AddThis Social Bookmark Button