Skip to main content
Inspiring
December 15, 2008
Question

on(keypress ...)... how to use keycode?

  • December 15, 2008
  • 2 replies
  • 513 views
Hi all,
I need to update an old application where I can to control some objects at
runtime.
The old application used the

on(keypress "<right>") {
bla;
bla;
bla;
}

to move the selected object to the right.
All went ok this way.

But now I need to use the numpad keys to move the object along diagonals,
up, down, right and left.

Is there a way to use the keypress command and specify a character code for
the numpad keys?

I've read the livedocs on adobe websites but it seems I need to rewrite the
whole thing.

Is there a simpler way to update this application without rewriting it from
the ground up?

TIA

tony
This topic has been closed for replies.

2 replies

Inspiring
December 16, 2008
> You should be able to use the ASCII key codes to control your object.[snip]
> Damien

Thx, Damien,
do you know the right syntax to use with "keypress"; I tried everything:

on(keypress 102){
bla...;
bla...;
bla...;
}

or

on(keypress "102"){
bla...;
bla...;
bla...;
}

or

on(keypress charcode(102)){
bla...;
bla...;
bla...;
}
...
...but nothing worked...

Ciao ;).

tony
Inspiring
December 17, 2008
I think this is what your after.

http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001136.html

In this code, they are creating a listener to listen for the keydown event in which they run that function that gets the key codes and/or ASCII codes. From this you could create if statements to control your object based on the keycodes your code "gets".

You may have to do a little bit of fiddling with your sequence of functions but shouldnt be 2 hard.

Hope this helps you.

Damien
Inspiring
December 15, 2008
You should be able to use the ASCII key codes to control your object. If not im sure you can build a listener that can listen for the ASCII codes you are after and run each function as it recieves them, I could be wrong but hope this helps

Damien