Friday, February 13, 2009

Keyboard

Hello there ! i've been posting a lot of useful stuff in here right ?!
So now it's time for the keyboard.

So, you want things to happen if you press a key on the keyboard ? - Easy !
i'm gonna teach you 2 ways, 1 limited easy way, and one limitless not that easy.

one way to do that is:

if (Key.isDown ( Key._____ )) {

now, you see that blank space ? many things can go there. You can type:

BACKSPACE, CAPSLOCK, CONTROL, DELETEKEY, DOWN, END, ENTER, ESCAPE, HOME, INSERT, LEFT, PGDN, PGUP, RIGHT, SHIFT, SPACE, TAB AND UP.

an example of using this way is:

if (Key.isDown (Key.PGUP)) {
_root.page._y += speed;
}

that means that, when i press page up, the page mc is going up. Now, if you dont want none of this keys, for example if you want your char to move with WASD keys, you have to get the key's ASCII, wich is a number that refers to 1 key. Lucky for you, i prepared a flash that tells you the ASCII, it will be on the bottom of this post. Well, once you got the numbers, use this actions:

watchKeyBoard = new Object();
watchKeyBoard.onKeyDown = function() {
if (Key.getAscii() == ___) {
_________________________;
}
}
Key.addListener(watchKeyBoard);


The first blank space is where you type your ascii code, and that second is what happens when you press the key. Easy ? Here is the ASCII receiver i made:







you may have to click it so it can work

0 comments:

Post a Comment