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 our datasets.
- var names:Array = ["apple", "osx", "ios", "microsoft", "windows", "xbox", "linux"];
- var frames:Array = [2, 2, 2, 3, 3, 3, 4];
- function keyboardHandler(e:KeyboardEvent):void {
- var txt:TextField = e.currentTarget as TextField;
- var lowercase:String = txt.text.toLowerCase();
- var i:int;
- if (e.charCode == 13) { // Enter Key
- for (i = 0; i < names.length; i++) {
- if (lowercase == names[i]) {
- break; // stop the search, since we found the match.
- }
- }
- // If the break didn't occur, "i" would reach names.length
- if (i == names.length) {
- trace("No match found. :(");
- } else {
- trace("Going to frame " + frames[i]);
- gotoAndStop(frames[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement