2009-02-18 62 views
0

如何防止CTRL + 一个从可编辑的文本字段()文本字段()防止CTRL + A(全选)

+0

你可以在你要完成的任务上增加一点背景吗?也许TextField不是该作业的正确控件? – StingyJack 2009-02-18 13:19:27

+0

好吧,它的完美ctrl我只想删除CTRL + A。 – Tom 2009-02-19 10:10:11

+0

听起来像你想做的事情,你不应该做的。你能解释一下你想做这件事的原因是什么? – troelskn 2009-02-19 12:20:47

回答

1

前面的示例仅适用于Flex文本和TextArea对象,它适用于所有flash.text。*对象。

<?xml version="1.0" encoding="utf-8"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()"> 
    <mx:Script> 
     <![CDATA[ 
      import mx.core.UIComponent; 

      private var t:TextField; 
      private function init():void 
      { 
       t = new TextField(); 
       t.height = 80; 
       t.width = 100; 
       t.type = TextFieldType.INPUT; 
       t.multiline = true; 
       var c:UIComponent = new UIComponent(); 
       c.addChild(t); 
       foo.addChild(c); 
       addEventListener(KeyboardEvent.KEY_UP,   edit); 
       addEventListener(KeyboardEvent.KEY_DOWN,  edit); 
      } 

      private function edit(event:KeyboardEvent):void 
      { 
       if(event.type == KeyboardEvent.KEY_DOWN && event.ctrlKey) 
       { 
        t.type = TextFieldType.DYNAMIC; // Dynamic texts cannot be edited. You might be able to remove this line. 
        t.selectable = false; // If selectable is false, then Ctrl-a won't do anything. 
       } 
       else 
       { 
        t.type = TextFieldType.INPUT; 
        t.selectable = true; 
       } 
      } 
     ]]> 
    </mx:Script> 
    <mx:Canvas id="foo" height="90" width="110" backgroundColor="#FFFFFF" /> 
</mx:Application> 
0

没有测试工作,但也许你可以捉对TextFieldselectAll event和防止它冒泡,或清除选择(不知道事件何时被触发)。

0

使用与听众的KeyboardEvent配对的setFocus功能:

<xml version="1.0"?> 
<!-- menus/SimpleMenuControl.mxml --> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="800" initialize="init()" > 
    <mx:TextInput id="nom"/> 
    <mx:Script> 
     <![CDATA[ 
      private function init():void 
      { 
       addEventListener(KeyboardEvent.KEY_UP,  edit); 
       addEventListener(KeyboardEvent.KEY_DOWN, edit); 
      } 

      private function edit(event:KeyboardEvent):void 
      { 
       if(event.type == KeyboardEvent.KEY_DOWN && event.ctrlKey) setFocus(); 
       else nom.setFocus(); 
       nom.selectionEndIndex = nom.selectionBeginIndex = nom.text.length; 
      } 
     ]]> 
    </mx:Script> 

</mx:Application> 

的的setFocus意味着该文本对象将不再听任何键盘事件。

我不会推荐使用启用的属性,因为这会灰色的textarea。

相关问题