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