RichTextEditor コントロール

RichTextEditor コントロールを使用すると、ユーザーがテキストを入力、編集、およびフォーマットできます。ユーザーは、RichTextEditor コントロールの下部に表示されるサブコントロールを使用して、テキストフォーマットや URL リンクを適用します。

詳細については、『Adobe Flex 2 リファレンスガイド』の RichTextEditor を参照してください。

サブトピック

RichTextEditor コントロールについて
RichTextEditor コントロールの作成
RichTextEditor コントロールのサイズ設定
RichTextEditor サブコントロールのプログラミング

RichTextEditor コントロールについて

RichTextEditor コントロールは、Panel コントロールと 2 つの直系の子で構成されています。

次の図は、フォーマットされたテキストを持つ RichTextEditor コントロールを示しています。


スタイルを設定した RichTextEditor コントロール

この例のソースの詳細については、RichTextEditor コントロールの作成を参照してください。

RichTextEditor は、次に示すとおりインタラクティブに使用します。

RichTextEditor コントロールの作成

RichTextEditor コントロールは、次の例に示すように、<mx:RichTextEditor> タグを使用して MXML 内で定義します。MXML の他の場所 (他のタグまたは ActionScript ブロック) のコントロールを参照する場合は、id 値を指定します。

<?xml version="1.0"?>
<!-- textcontrols/RichTextEditorControl.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
  <mx:RichTextEditor id="myRTE" text="Congratulations, winner!" />
</mx:Application>

フォーマットされていないテキストストリングを指定する場合は text プロパティを使用し、HTML 形式のストリングを指定する場合は htmlText プロパティを使用します。これらのプロパティの使用の詳細については、text プロパティの使用およびhtmlText プロパティの使用を参照してください。コントロール内でのテキストの選択、置換、フォーマットの詳細については、テキストの選択と修正を参照してください。

次の例では、RichTextEditor コントロールについての図を作成するためのコードを示しています。

<?xml version="1.0"?>
<!-- textcontrols/RichTextEditorControlWithFormattedText.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="700"
height="400">
  <!-- The HTML text string used to populate the RichTextEditor control's
     TextArea subcontrol. The text is on a single line. -->
  <mx:Script><![CDATA[
     [Bindable]
     public var htmlData:String="<textformat leading='2'><p align='center'><b><font size='20'>HTML Formatted Text</font></b></p></textformat><br><textformat leading='2'><p align='left'><font face='_sans' size='12' color='#000000'>This paragraph contains<b>bold</b>, <i>italic</i>, <u>underlined</u>, and <b><i><u>bold italic underlined </u></i></b>text.</font></p></textformat><br><p><u><font face='arial' size='14' color='#ff0000'>This a red underlined 14-point arial font with no alignment set.</font></u></p><p align='right'><font face='verdana' size='12' color='#006666'><b>This a teal bold 12-pt.' Verdana font with alignment set to right.</b></font></p><br><li>This is bulleted text.</li><li><font face='arial' size='12' color='#0000ff'><u> <a href='http://www.adobe.com'>This is a bulleted link with underline and blue color set.</a></u></font></li>";
  ]]></mx:Script>

  <!-- The RichTextEditor control. To reference a subcontrol prefix its ID with the RichTextEditor control ID. -->
  <mx:RichTextEditor id="rte1" 
     backgroundColor="#ccffcc" 
     width="605"
     headerColors="[#88bb88, #bbeebb]" 
     footerColors="[#bbeebb, #88bb88]" 
     title="Rich Text Editor" 
     htmlText="{htmlData}" 
     initialize="rte1.textArea.setStyle('backgroundColor', '0xeeffee')"
  />
</mx:Application>

RichTextEditor コントロールのサイズ設定

RichTextEditor コントロールには、次のデフォルトのサイズ変更プロパティがあります。

プロパティ

デフォルト値

デフォルトサイズ

幅 325 ピクセル、高さ 300 ピクセル

最小サイズ

幅 220 ピクセル、高さ 200 ピクセル

最大サイズ

10000 x 10000 ピクセル

このコントロールは、TextArea コントロールのテキストのサイズに応じてサイズ変更されることはありません。テキストが表示可能なスペースを超えた場合、デフォルトでは、TextArea コントロールによりスクロールバーが追加されます。height または width プロパティのいずれか (両方ではない) の値を指定すると、コントロールでは、設定していないプロパティに対してデフォルト値が使用されます。

設定した width 値により、幅が 605 ピクセル未満になる場合、RichTextEditor コントロールでは、サブコントロールが連続してスタックされます。


Flex 2.01