Scott Ruttencutter - What The Flash?

Digital Complement to the Moleskine
  • rss
  • Home
  • About

Flash AS3 - CharCodeStrings Library (download)

A few weeks ago I was working on an interesting text typing widget for our new website (that isn’t up yet, still in the works). I came to find that there was a Keyboard.CharCodeStrings Array Constant in the AS3 Language reference–but it was only available within the AIR 1.0 runtime. Bummer.

So like many folks out there, I needed to roll a homegrown solution to match up CharCode result numbers with their character counterparts. Essentially a singleton class that you can use when you catch your event and turn the resulting CharCode into a literal string character.

Here is an example:

  1. package {
  2.  import flash.events.KeyboardEvent;
  3.  import flash.display.MovieClip;
  4.  import com.iq.CharCodeStrings;
  5.  public class CharCodeStrings_sample extends MovieClip {
  6.  
  7.   public function CharCodeStrings_sample() {
  8.    stage.addEventListener(KeyboardEvent.KEY_DOWN, traceKey);
  9.   }
  10.   public function traceKey(event:KeyboardEvent):void {
  11.    var myChar:String = CharCodeStrings.getChar(event.charCode);
  12.    trace(myChar);
  13.   }
  14.  }
  15. }

If this may be useful to you, there is a download link below. I built this to do what I needed for the project I was working on, so the character codes returned are for US English–but you could easily substitute another language by using the included sample app and replacing the characters. If you do set this up for use in another language feel free to shoot me the file and I will link it here.

Download CharCodeStrings

(Hint, when testing from within the Flash IDE turn off Keyboard Shortcuts when you run your movie to test or the preview window may not receive keyboard input. It is in the Control menu when your swf is playing.)

Categories
Flash
Tags
Flash, Free AS3 Code
Comments rss
Comments rss
Trackback
Trackback

« Google Maps API for Flash! levelHead - Spatial Reality Game »

3 responses

[...] but then found out that it is only available

Away3D Typewriter : timovirtanen.com

[...] but then found out that it is only available within the AIR 1.0 runtime. Fortunately I found Scott Ruttencutters CharCodeStrings Library (download). Thanks for sharing it Scott [...]

Looks like your class only handles printable ASCII characters (no

hwuag

Looks like your class only handles printable ASCII characters (no “page up”, “left arrow”, etc). In that case, why not just use String.fromCharCode()?

You, sir, Win the game. Why adobe would hide

admin

You, sir, Win the game. Why adobe would hide a function in the string Class is beyond me. Thanks for pointing it out.

Leave a comment

You can use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Categories

  • Amazing Work
  • Cliché
  • Flash
  • PHP
  • Uncategorized

Links

  • IQ Foundry
  • IQ Games
  • Sticker Foundry
  • Time IQ

Meta

  • Log in
  • Entries RSS
  • Comments RSS
rss Comments rss valid xhtml 1.1 powered by Wordpress get firefox