7 Replies Latest reply on Oct 26, 2010 7:42 AM by kglad

    Restrict "Enter, delete and backspace" in TextArea

    A.kameshwaran Level 1

      Hi,

           I want to restrict Delete key, Backspace key,  and Enter Key in TextArea. Please tell me how to restrict these 3 keys. Thanks in advance.

       

      Regards,

      Kameshwaran A

        • 1. Re: Restrict "Enter, delete and backspace" in TextArea
          kglad Adobe Community Professional & MVP

          use a key listener to do (or undo) what you want.

          • 2. Re: Restrict "Enter, delete and backspace" in TextArea
            A.kameshwaran Level 1

            Hi Kglad,

             

                 Thanks for the reply.

             

            This is my code. Please tell me, how can i restrict it.

             

            I have named my TextArea as my_txt.

             

            my_txt.text = "Cuveiro: resteba o restreba 'la segunda cosecha que se coge en un mismo terreno'.";
            listenerObject = new Object();

             

            // If i press delete key, first  this listener is invoking


            listenerObject.keyDown = function(eventObject){
                trace("keyDown");
                trace(my_txt.text);
               
            }

            // then this listener is invoking and the delete operation has performed. if i give return false, it is not stoping the delete operation.
            listenerObject.change = function(eventObject){
                 trace("change");
                trace(my_txt.text);
              
            }
            listenerObject.keyUp = function(eventObject){
                trace("keyUp");
                trace(my_txt.text);
               
            }
            my_txt.addEventListener("keyDown", listenerObject)
            my_txt.addEventListener("keyUp", listenerObject)
            my_txt.addEventListener("change", listenerObject)

             

            Please help to restrict the delete,enter and backspace key. Thanks

             

            Regards,

            Kameshwaran A

            • 3. Re: Restrict "Enter, delete and backspace" in TextArea
              kglad Adobe Community Professional & MVP

              what do you want each of those keys to do?


              • 4. Re: Restrict "Enter, delete and backspace" in TextArea
                A.kameshwaran Level 1

                For Users, It should not work inside textarea. So that they can't delete or break the line.

                • 5. Re: Restrict "Enter, delete and backspace" in TextArea
                  kglad Adobe Community Professional & MVP

                  var origS:String = "Cuveiro: resteba o restreba 'la segunda cosecha que se coge en un mismo terreno'."

                   

                  my_txt.text = origS;

                   

                  listenerObject = new Object();

                   

                   

                  // If i press delete key, first  this listener is invoking

                   

                   

                  listenerObject.keyDown = function(eventObject) {

                   

                      ci = Selection.getCaretIndex();

                   

                  };

                   

                  listenerObject.keyUp = function(eventObject) {

                   

                      if(Key.getAscii()==13){
                          my_txt.text=my_txt.text.split("\r").join("");
                      } else if(Key.getAscii()==8 || Key.getAscii()==127){
                          if(prevS){
                              my_txt.text=prevS;
                          } else {
                              my_txt.text=origS
                          }
                      }
                      prevS = my_txt.text;
                      Selection.setFocus(my_txt);
                      Selection.setSelection(ci,ci)
                  };

                   

                  my_txt.addEventListener("keyDown",listenerObject);
                  my_txt.addEventListener("keyUp",listenerObject);
                  • 6. Re: Restrict "Enter, delete and backspace" in TextArea
                    A.kameshwaran Level 1

                    Thank you very much Kglad.

                    Please tell me one more thing for enter key. if already i have multi line text then in that case what i have to do.

                    • 7. Re: Restrict "Enter, delete and backspace" in TextArea
                      kglad Adobe Community Professional & MVP

                      use:

                       

                      var origS:String = "Cuveiro: resteba o \nrestreba 'la segunda cosecha que se coge en un mismo terreno'."
                      my_txt.text = origS;
                      listenerObject = new Object();

                       

                      listenerObject.keyDown = function(eventObject) {
                          ci = Selection.getCaretIndex();
                      };
                      listenerObject.keyUp = function(eventObject) {
                          if(Key.getAscii()==8 || Key.getAscii()==127 || Key.getAscii()==13){
                              if(prevS){
                                  my_txt.text=prevS;
                              } else {
                                  my_txt.text=origS
                              }
                              Selection.setFocus(my_txt);
                              Selection.setSelection(ci,ci)
                          }
                          prevS = my_txt.text;
                      };

                       

                      my_txt.addEventListener("keyDown",listenerObject);
                      my_txt.addEventListener("keyUp",listenerObject);