Advertisement
Guest User

onChange

a guest
Jun 28th, 2012
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import flash.text.TextField;
  2. import flash.text.TextFieldType;
  3. import flash.text.TextFormat;
  4. import flash.events.Event;
  5. import flash.events.KeyboardEvent;
  6. import flash.ui.Keyboard;
  7.  
  8. // variable to store what the user types
  9. var whatIsTyped:String = '';
  10.  
  11. // create input text field
  12. var myInput:TextField = new TextField();
  13. myInput.type = TextFieldType.INPUT;
  14. myInput.width = 300;
  15. myInput.height = 25;
  16. myInput.x = myInput.y = 10;
  17. myInput.defaultTextFormat = new TextFormat("Arial",18,0x0,true);
  18. myInput.border = true;
  19. addChild(myInput);
  20.  
  21. // add listeners, one for change, one for enter
  22. myInput.addEventListener(Event.CHANGE, changeHandler);
  23. stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
  24.  
  25. // handle changes, adding them to var whatIsTyped
  26. function changeHandler(e:Event):void
  27. {
  28.     // just update var
  29.     whatIsTyped = myInput.text;
  30.        
  31.     // you could check the value here if you wish too
  32.     // for every keystroke
  33. }
  34.  
  35. // just find "ENTER"
  36. function keyPressed(e:KeyboardEvent):void
  37. {
  38.     if (e.keyCode == Keyboard.ENTER)
  39.     {
  40.         // analyze
  41.         trace("Analyze: " + whatIsTyped);
  42.     }
  43. }
  44.  
  45.  
  46. // focus it, no caret seen because you need to touch a flash
  47. // window to Activate it (win32 rule), but you can type
  48. addEventListener(Event.ENTER_FRAME, handleEnterFrame);
  49.  
  50. function handleEnterFrame(e:Event):void
  51. {
  52.     removeEventListener(Event.ENTER_FRAME, handleEnterFrame);
  53.     stage.focus = myInput;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement