Flash Lite 2 |
|||
| Flash Lite 2.x ActionScript リファレンスガイド > ActionScript クラス > TextField > setTextFormat (TextField.setTextFormat メソッド) | |||
public setTextFormat([beginIndex: Number], [endIndex: Number], textFormat: TextFormat) : Void
textFormat パラメータにより指定されたテキストフォーマットを、テキストフィールド内のテキストの一部または全体に適用します。textFormat には、目的のテキストフォーマット変更を指定する TextFormat オブジェクトを指定する必要があります。textFormat の null 以外のプロパティのみがテキストフィールドに適用されます。textFormat で null に設定されているプロパティは適用されません。デフォルトで、新しく作成された TextFormat オブジェクトのプロパティはすべて null に設定されます。
TextFormat オブジェクトのフォーマット情報には、文字レベルフォーマットと段落レベルフォーマットの 2 種類があります。テキストフィールド内の各文字にも、フォント名やフォントサイズ、ボールド、イタリックなどの文字固有のフォーマット設定があります。
段落の場合は、段落の最初の文字を調べて段落全体のフォーマット設定を決定します。段落のフォーマット設定には、左マージン、右マージン、インデントなどがあります。
setTextFormat() メソッドは、テキストフィールドの各文字、文字の範囲、またはテキスト全体に適用するテキストフォーマットを変更します。
textFormat のプロパティをテキストフィールドのすべてのテキストに適用します。
textFormat のプロパティを beginIndex 位置の文字に適用します。
textFormat パラメータのプロパティを beginIndex 位置から endIndex 位置までのテキスト範囲に適用します。
ユーザーによって手作業で挿入されたテキストは、テキストの挿入か所に指定されているフォーマットではなく、新しいテキスト用のテキストフィールドのデフォルトフォーマットが適用されます。新しいテキスト用のテキストフィールドのデフォルトフォーマットを設定するには、TextField.setNewTextFormat() を使用します。
使用できるバージョン : ActionScript 1.0、Flash Lite 2.0
beginIndex: Number (オプション) - 該当するテキスト範囲の最初の文字を指定する整数。beginIndex および endIndex を指定しない場合、TextFormat は TextField 全体に適用されます。
endIndex: Number (オプション) - 該当するテキスト範囲の直後の文字を指定する整数。beginIndex を指定して endIndex を指定しない場合、TextFormat は beginIndex で指定された 1 つの文字に適用されます。
textFormat: TextFormat - 文字と段落のフォーマット情報を含む TextFormat オブジェクト。
次の例では、テキストの 2 つの異なるストリングにテキストフォーマットを設定します。setTextFormat() メソッドを呼び出し、my_txt テキストフィールドに適用します。
var format1_fmt: TextFormat = new TextFormat();
format1_fmt.font = "Arial";
var format2_fmt: TextFormat = new TextFormat();
format2_fmt.font = "Courier";
var string1: String = "Sample string number one."+newline;
var string2: String = "Sample string number two."+newline;
this.createTextField("my_txt", this.getNextHighestDepth(), 0, 0, 300, 200);
my_txt.multiline = true;
my_txt.wordWrap = true;
my_txt.text = string1;
var firstIndex: Number = my_txt.length;
my_txt.text += string2;
var secondIndex: Number = my_txt.length;
my_txt.setTextFormat(0, firstIndex, format1_fmt);
my_txt.setTextFormat(firstIndex, secondIndex, format2_fmt);
, TextFormat, setNewTextFormat (TextField.setNewTextFormat メソッド)