开发者

I don't want to allow linewise scrolling in textArea in noneditable mode

开发者 https://www.devze.com 2022-12-22 14:40 出处:网络
I d开发者_高级运维on\'t want to allow linewise scrolling(means through arrow key) in textArea in noneditable modeWithout having time to actually write the code, here\'s what I would do conceptually:

I d开发者_高级运维on't want to allow linewise scrolling(means through arrow key) in textArea in noneditable mode


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消