简体   繁体   中英

How to identifiy if a text is selected in a mx textinput flex

Can any one please tell me how to check whether the text in a mx textinput control is selected or not.I have some controls like mx textinput, mx textara and richtexteditor. selection comes from when user drags it or double click on any control the selection highlights at that time i want to know which control is selected.I have seen the solution for spark textinput which is posted in stackoverflow How to access the selected text in a Flex TextInput control but i want for mx components.Please tell me how to know which control text is selected for textinput,textarea and richtexteditor controls. Thanks

For TextInput and 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);

For 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;

This will check if the component has any selected text, but not whether the component is selected; the text selection stays even when the component loses focus . The easy way to check if the component actually has focus is by setting a boolean flag in the component's focusIn and focusOut events. You could also deselect the text in a focusOut event:

component.selectionEndIndex = 0; // clear selection

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM