| パッケージ | flash.text.engine |
| クラス | public final class TextElement |
| 継承 | TextElement ContentElement Object |
| 言語バージョン: | ActionScript 3.0 |
| ランタイムバージョン: | Flash Player 10, AIR 1.5, Flash Lite 4 |
content プロパティに割り当て、テキストのブロックを作成します。GroupElement オブジェクトに割り当てて、単位として他のテキストエレメントまたはグラフィックエレメントと結合します。テキストをフォーマットするには、ElementFormat クラスを使用します。
関連する API エレメント
パブリックプロパティ
| プロパティ | 定義元 | ||
|---|---|---|---|
![]() | constructor : Object
指定されたオブジェクトインスタンスのクラスオブジェクトまたはコンストラクター関数への参照です。 | Object | |
![]() | elementFormat : ElementFormat
エレメントに使用される ElementFormat オブジェクトです。 | ContentElement | |
![]() | eventMirror : EventDispatcher
このコンテンツエレメントに基づいた有効なテキスト行に送出されるすべてのイベントのコピーを受け取る EventDispatcher オブジェクトです。 | ContentElement | |
![]() | groupElement : GroupElement [読み取り専用]
このエレメントを含む GroupElement オブジェクトです。グループ内に存在しない場合は null になります。 | ContentElement | |
![]() | rawText : String [読み取り専用]
任意の U+FDEF 文字を含む、エレメント内のテキストのコピーです。 | ContentElement | |
| text : String
エレメントのコンテンツであるテキストを受け取ります。 | TextElement | ||
![]() | textBlock : flash.text.engine:TextBlock [読み取り専用]
このエレメントが含まれる TextBlock です。 | ContentElement | |
![]() | textBlockBeginIndex : int [読み取り専用]
このエレメントの最初の文字のテキストブロック内のインデックスです。 | ContentElement | |
![]() | textRotation : String
エレメントを単位として適用される回転です。 | ContentElement | |
![]() | userData : *
アプリケーションが任意のデータをエレメントに関連付けるための方法を提供します。 | ContentElement | |
パブリックメソッド
| メソッド | 定義元 | ||
|---|---|---|---|
TextElement(text:String = null, elementFormat:ElementFormat = null, eventMirror:EventDispatcher = null, textRotation:String = "rotate0")
新しい TextElement インスタンスを作成します。 | TextElement | ||
![]() |
オブジェクトに指定されたプロパティが定義されているかどうかを示します。 | Object | |
![]() |
Object クラスのインスタンスが、パラメーターとして指定されたオブジェクトのプロトタイプチェーン内にあるかどうかを示します。 | Object | |
![]() |
指定されたプロパティが存在し、列挙できるかどうかを示します。 | Object | |
beginIndex パラメーターと endIndex パラメーターで指定された文字範囲を、newText パラメーターの内容に置き換えます。 | TextElement | ||
![]() |
ループ処理に対するダイナミックプロパティの可用性を設定します。 | Object | |
![]() |
ロケール固有の規則に従って書式設定された、このオブジェクトのストリング表現を返します。 | Object | |
![]() |
指定されたオブジェクトのストリング表現を返します。 | Object | |
![]() |
指定されたオブジェクトのプリミティブな値を返します。 | Object | |
パブリック定数
プロパティの詳細
text | プロパティ |
コンストラクターの詳細
TextElement | () | コンストラクター |
public function TextElement(text:String = null, elementFormat:ElementFormat = null, eventMirror:EventDispatcher = null, textRotation:String = "rotate0")| 言語バージョン: | ActionScript 3.0 |
| ランタイムバージョン: | Flash Player 10, AIR 1.5, Flash Lite 4 |
新しい TextElement インスタンスを作成します。
パラメーターtext:String (default = null) — エレメントのテキストです。デフォルト値は null です。
| |
elementFormat:ElementFormat (default = null) — エレメント内のテキストのエレメント形式です。デフォルト値は null です。
| |
eventMirror:EventDispatcher (default = null) — このコンテンツエレメントに基づいたテキスト行に送出されるすべてのイベントのコピーを受け取る EventDispatcher オブジェクトです。デフォルト値は null です。
| |
textRotation:String (default = "rotate0") — エレメントを単位として適用される回転です。このプロパティには、TextRotation 定数を使用します。デフォルト値は、TextRotation.ROTATE_0 です。
|
例 ( この例の使用方法 )
次の例では、テキストのストリングから TextElement オブジェクトを作成し、フォントサイズ 12 と赤(0xCC0000)でフォーマットし、TextBlock の
content プロパティに割り当てます。createLines() 関数を呼び出して、テキストのブロックを改行して、それぞれ 150 ピクセルの行にします。
package {
import flash.display.Sprite;
import flash.text.engine.TextBlock;
import flash.text.engine.TextElement;
import flash.text.engine.TextLine;
import flash.text.engine.ElementFormat;
public class TextElementExample extends Sprite {
public function TextElementExample():void {
var str:String = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, " +
"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut " +
"enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut " +
"aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit " +
"in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur " +
"sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt " +
"mollit anim id est laborum.";
var format:ElementFormat = new ElementFormat(null, 12, 0xCC0000);
var textElement:TextElement = new TextElement(str, format);
var textBlock:TextBlock = new TextBlock();
textBlock.content = textElement;
createLines(textBlock);
}
private function createLines(textBlock:TextBlock):void {
var yPos = 20;
var textLine:TextLine = textBlock.createTextLine (null, 150);
while (textLine)
{
addChild(textLine);
textLine.x = 15;
yPos += textLine.textHeight+2;
textLine.y = yPos;
textLine = textBlock.createTextLine(textLine, 150);
}
}
}
}
メソッドの詳細
replaceText | () | メソッド |
public function replaceText(beginIndex:int, endIndex:int, newText:String):void| 言語バージョン: | ActionScript 3.0 |
| ランタイムバージョン: | Flash Player 10, AIR 1.5, Flash Lite 4 |
beginIndex パラメーターと endIndex パラメーターで指定された文字範囲を、newText パラメーターの内容に置き換えます。beginIndex と endIndex の値は、text の現在のコンテンツを参照します。
テキストを削除するには、null を newText に渡します。
テキストを挿入するには、beginIndex および endIndex に同じ値を渡します。新しいテキストは、指定されたインデックスの前に挿入されます。
テキストを追加するには、text.length を beginIndex および endIndex に渡します。
すべてのテキストを設定するには、0 を beginIndex に渡し、text.length を endIndex に渡します。
パラメーター
beginIndex:int — 置換範囲の開始位置の 0 から始まるインデックス値です。
| |
endIndex:int — 置換範囲の終了位置に後続する位置の 0 ベースのインデックス値です。
| |
newText:String — 指定された文字範囲の置き換えに使用されるテキストです。
|
例外
RangeError — 指定された beginIndex または endIndex は範囲外です。
|
例 ( この例の使用方法 )
この例は、
replaceText() を複数回呼び出して、以下を実行します。
- テキストの起点にストリングを挿入
- テキストの最後にストリングを追加
- テキストの途中にストリングを挿入
- テキストを新しいテキストで完全に置き換え
package {
import flash.display.Sprite;
import flash.text.engine.FontDescription;
import flash.text.engine.ElementFormat;
import flash.text.engine.TextElement;
import flash.text.engine.TextBlock;
import flash.text.engine.TextLine;
public class TextElement_replaceTextExample extends Sprite {
public function TextElement_replaceTextExample():void {
var str:String = "0123456";
var fontDescription:FontDescription = new FontDescription("Arial");
var format:ElementFormat = new ElementFormat(fontDescription);
format.fontSize = 14;
var textElement:TextElement = new TextElement(str, format);
var textBlock:TextBlock = new TextBlock();
textBlock.content = textElement;
textElement.replaceText(0, 0, "abc");
createLine(textBlock, 20); //"abc0123456"
textElement.replaceText(10, 10, "abc");
createLine(textBlock, 40); // "abc0123456abc"
textElement.replaceText(5, 8, "abc");
createLine(textBlock, 60); // "abc01abc56abc"
textElement.replaceText(0, 13, "abc");
createLine(textBlock, 80); // "abc"
textElement.replaceText(0, 3, "That's all she wrote!");
createLine(textBlock, 100); // "That's all she wrote" */
}
private function createLine(textBlock:TextBlock, y:Number):void {
var textLine:TextLine = textBlock.createTextLine(null, 150);
textLine.x = 10;
textLine.y = y;
addChild(textLine);
}
}
}
Tue Jun 12 2018, 10:34 AM Z
継承されるパブリックプロパティを隠す
継承されるパブリックプロパティを表示