Some favorite site feeds aggregated locally: iPhone Development RSS   Adobe Labs RSS   Macrumors RSS

Wednesday, June 11, 2008

Number.fromCharCode

Wednesday, June 11, 2008   

We've all been acquainted with String.fromCharCode in relationship to event.keyCode, but it also works with Number. Why would you want to do that?

Well, I am getting sets of keyboard inputs as keyCodes from a piece of hardware, and I build up an angle to use. A delimiter lets me know when to stop per each set.

In order to translate the keyCodes back to numbers for use in building up the angle to use, instead of using a method to translate the keyCodes to a Number to use, you can simply do something like this:

var code:Number = event.keyCode;
var n:Number = Number.fromCharCode( code );

And from this I build up an array, looking for a delimiter all the time, and when I get the delimiter, build the angle number and use it. Of course this fails if you are getting keyCodes that are out of range of 0-9, so you need to filter your keyCodes as they come in.

I haven't seen any public code (yet) that uses Number.fromCharCode yet, and for me it works perfectly, so I thought I'd throw this out there.

Labels: ,

 
 Return to the main page
Comments:

There are currently 0 Comments:

 Leave a comment