任何人都可以告诉我如何检查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控件选择了哪个控件文本。 感谢
答案 0 :(得分:1)
TextInput
和TextArea
:
// 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;
这将检查组件是否有任何选定的文本,但不检查组件是否被选中;即使组件失去焦点,文本选择仍保持 。检查组件是否实际具有焦点的简单方法是在组件的focusIn
和focusOut
事件中设置布尔标志。您还可以取消选择focusOut
事件中的文字:
component.selectionEndIndex = 0; // clear selection