Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import flash.text.TextField;
- import flash.text.TextFormat;
- import flash.events.KeyboardEvent;
- // Style for our TextField
- var inputTextFormat:TextFormat = new TextFormat();
- inputTextFormat.font = "Consolas";
- inputTextFormat.size = 14;
- // Create our TextField and let us type in it.
- var text_in:TextField = new TextField();
- text_in.defaultTextFormat = inputTextFormat;
- text_in.selectable = true;
- text_in.type = "input";
- text_in.text = "Type Here";
- text_in.addEventListener(KeyboardEvent.KEY_UP, keyboardHandler); // listen for the enter key
- addChild(text_in)
- // Create an object with arrays for each key.
- var list:Object = {
- "2":["apple", "osx", "ios"],
- "3":["microsoft", "windows", "xbox"],
- "4":["linux"]
- }
- function keyboardHandler(e:KeyboardEvent):void {
- var txt:TextField = e.currentTarget as TextField;
- var lowercase:String = txt.text.toLowerCase();
- var answer:int = -1;
- if (e.charCode == 13) { // Enter Key
- for (var key:String in list) {
- if (answer != -1) { break; } // Stop the search if we found a match.
- for (var i:int = 0; i < list[key].length; i++) {
- if (lowercase == list[key][i]) {
- answer = int(key);
- break;
- }
- }
- }
- // If the break didn't occur, "i" would reach names.length
- if (answer == -1) {
- trace("No match found. :(");
- } else {
- trace("Going to frame " + answer);
- gotoAndStop(answer);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement