tags:

views:

86

answers:

1

I don't want to allow linewise scrolling(means through arrow key) in textArea in noneditable mode

A: 

Without having time to actually write the code, here's what I would do conceptually:

  1. If your TextArea is not editable, add an EventListener that checks to see if the TextArea currently has focus. When the TextArea has the focus your EventListener should create another EventListener that looks for a keyboard event.

  2. In your keyboard event EventListener, check to see if the key that was pressed was an arrow key. If it was an arrow key, trap the event and do nothing.

  3. When the TextArea loses focus, remove the EventListener that checks for the arrow keys being pressed.

I hope this helps!

Edit: When a key is pressed on the keyboard, it has a specific keyCode Flex can use to tell which key was pressed. The arrow keys are 37 - 40.

To take from an example (from the Adobe Live Docs):

<mx:Script>
  <![CDATA[
    private function initApp():void {
        myTextArea.addEventListener(KeyboardEvent.KEY_UP, keyHandler);
    }

    private function keyHandler(event:KeyboardEvent):void {
        if(event.keyCode >= 37 && event.keyCode <= 40)
        {
          event.stopImmediatePropagation();
        }
    }
  ]]>
</mx:Script>
Jason Towne
thanks for this answer
Ankur
No worries. If this helped answer your question, please mark it as an accepted answer so it might help others as well. :)
Jason Towne
thanks for this answer.... i have used this solution but i want no operation on arrow key......
Ankur
In the *Do Something* part of the example I used, try `event.stopImmediatePropagation();`. I edited my example to include that line. I hope it helps!
Jason Towne
I have also tried event.stopImmediatePropagation(); but it is not working . After using your example, cursor event is capturing but cursor is moving.....
Ankur
I think this may be a bubbling issue. I've edited my example again to put the `eventListener` on the `TextArea` instead of the application.
Jason Towne