2011-09-22 36 views
0

用户需要能够将Excel电子表格的内容粘贴到我的Flex应用程序的网格中。不可编辑的文本粘贴目标

我已经使用TextAreachange事件处理程序,分析文本的用户粘贴实现这一点 - 它分裂上升换行符和标签 - 并将其添加到绑定到电网的ArrayCollection

但是,用户无法在TextArea中手动输入文本是没有意义的。我怎样才能防止他们这样做?

或者:创建我自己的组件实现IFocusManagerComponent会更有意义吗?

+0

这将是最好的,如果你有一个'Validator'这表明如果TextArea中的文本无效,则会发生错误。 –

回答

0

[更新] 有点乱,请清理使用前代码:

<fx:Script> 
    <![CDATA[ 

     protected function keyDownEvent(e:KeyboardEvent):void 
     { 
      e.preventDefault(); 
      switch(e.keyCode) 
      { 
       case Keyboard.V: 
        if (e.ctrlKey) 
        { 
         ta.text += "Some dummy " + "\n" + 
          "text pasted in this text area"; 
         ta.text += "\n[Keyboard Used to paste]"; 
        } 
        break; 
       default: 
        e.preventDefault(); 
      } 
     } 

     protected function onCreationComplete(event:Event):void 
     { 
      ta.addEventListener(KeyboardEvent.KEY_DOWN, keyDownEvent); 
     } 

    ]]> 
</fx:Script> 

<s:Label text="Press CTRL[V] to see the action"/> 
<s:TextArea id="ta"/>