Advertisement
Guest User

Untitled

a guest
Sep 14th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. mykey = new Object();
  2. mykey.onChanged = function(in_txt:TextField) {
  3.     trace("onChange: "+String.fromCharCode(Key.getAscii()));
  4.     trace("FIX: "+in_txt.text.length+" : "+fixlength);
  5.     if(fixchar and in_txt.text.length >= fixlength+2/* and in_txt.text.charAt(in_txt.length-1) == "@"*/){
  6.         in_txt.text = in_txt.text.substr(0,in_txt.text.length-2)+"@";
  7.         Selection.setSelection(in_txt.text.length, in_txt.text.length);
  8.     }
  9.     fixlength = in_txt.text.length;
  10.     fixchar = false;
  11. }
  12. input_email.mytf.addListener(mykey);
  13. fixlength = 0;
  14. setkeyfix = function(){
  15.     mykey2 = new Object();
  16.     mykey2.onKeyDown = function(){
  17.         var myexclude = new Array(8,13,27,32,45,46,43,95,127,64);
  18.         if(Key.isDown(17) || Key.isDown(18)){
  19.             /*trace("oldkeydown YES: "+oldkeydown);
  20.             trace("n1: "+Number(Key.getAscii()));
  21.             trace("n2: "+myexclude.in_array(Number(Key.getAscii())));*/
  22.             if(Number(Key.getAscii()) > 0 and !myexclude.in_array(Number(Key.getAscii()))){
  23.                 //if(String.fromCharCode(Key.getAscii()).length > 0 and String.fromCharCode(Key.getAscii()) != undefined){
  24.                     fixchar = true;
  25.                 //} else {
  26.                     trace("onKeyDown: "+String.fromCharCode(Key.getAscii()));
  27.                     input_email.mytf.text = input_email.mytf.text+"@";
  28.                    
  29.                     Selection.setSelection(input_email.mytf.text.length, input_email.mytf.text.length);
  30.                 //}
  31.             } else {
  32.                 fixchar = false;
  33.             }
  34.         } else {
  35.             fixchar = false;
  36.         }
  37.         //oldkeydown = Key.getCode();
  38.     }
  39.     Key.addListener(mykey2);
  40. }
  41. removekeyfix = function(){
  42.     Key.removeListener(mykey2);
  43.     delete mykey2;
  44. }
  45. input_email.setfocusfunc = function() {
  46.     setkeyfix();   
  47. }
  48. input_email.killfocusfunc = function() {
  49.     removekeyfix();
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement