1

mx textinputコントロールのテキストが選択されているかどうかを確認する方法を教えてください。mxtextinput、mx textara、richtexteditorなどのコントロールがあります。選択は、ユーザーがそれをドラッグするか、その時点で選択が強調表示されているコントロールをダブルクリックしたときに行われます。どのコントロールが選択されているか知りたいです。stackoverflowに投稿されたsparktextinputのソリューションを見てき ました。Flexで選択したテキストにアクセスする方法TextInputコントロール ですが、mxコンポーネントが必要です。textinput、textarea、richtexteditorコントロールにどのコントロールテキストが選択されているかを知る方法を教えてください。ありがとう

4

1 に答える 1

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
于 2012-06-06T20:51:45.913 に答える