如何识别是否在mx textinput flex中选择了文本

时间:2012-06-06 19:19:52

标签: actionscript-3 flex actionscript flex3

任何人都可以告诉我如何检查mx textinput控件中的文本是否被选中。我有一些控件,如mx textinput,mx textara和richtexteditor。选择来自用户拖动它或双击任何控件选项突出显示那时我想知道选择了哪个控件。我已经看到了spark textinput的解决方案,它发布在stackoverflow中 How to access the selected text in a Flex TextInput control 但我想要mx组件。请告诉我如何知道为textinput,textarea和richtexteditor控件选择了哪个控件文本。 感谢

1 个答案:

答案 0 :(得分:1)

TextInputTextArea

// to check for any selected text:
var hasSelection:Boolean = (component.selectionBeginIndex!=component.selectionEndIndex);
// to get the selected text:
var selection:String = component.text.substring(component.selectionBeginIndex,component.selectionEndIndex);

RichTextEditor

// to check for any selected text:
var hasSelection:Boolean = (component.selection.beginIndex!=component.selection.endIndex);
// to get the selected text:
var selection:String = component.selection.text;

这将检查组件是否有任何选定的文本,但不检查组件是否被选中;即使组件失去焦点,文本选择仍保持 。检查组件是否实际具有焦点的简单方法是在组件的focusInfocusOut事件中设置布尔标志。您还可以取消选择focusOut事件中的文字:

component.selectionEndIndex = 0; // clear selection
相关问题