パッケージflash.text.engine
クラスpublic final class TextElement
継承TextElement Inheritance ContentElement Inheritance Object

言語バージョン: ActionScript 3.0
ランタイムバージョン: Flash Player 10, AIR 1.5

TextElement クラスは、フォーマットされたテキストのストリングを表します。TextElement オブジェクトを、TextBlock オブジェクトの content プロパティに割り当て、テキストのブロックを作成します。GroupElement オブジェクトに割り当てて、単位として他のテキストエレメントまたはグラフィックエレメントと結合します。テキストをフォーマットするには、ElementFormat クラスを使用します。

関連項目

ContentElement
ElementFormat
TextBlock


パブリックプロパティ
 プロパティ定義元
 Inheritedconstructor : Object
指定されたオブジェクトインスタンスのクラスオブジェクトまたはコンストラクタ関数への参照です。
Object
 InheritedelementFormat : ElementFormat
エレメントに使用される ElementFormat オブジェクトです。
ContentElement
 InheritedeventMirror : EventDispatcher
このコンテンツエレメントに基づいた有効なテキスト行に送出されるすべてのイベントのコピーを受け取る EventDispatcher オブジェクトです。
ContentElement
 InheritedgroupElement : GroupElement
[読み取り専用] このエレメントを含む GroupElement オブジェクトです。グループ内に存在しない場合は null になります。
ContentElement
 Inheritedprototype : Object
[静的] クラスまたは関数オブジェクトのプロトタイプオブジェクトへの参照です。
Object
 InheritedrawText : String
[読み取り専用] U+FDEF 文字を含む、エレメント内のテキストのコピーです。
ContentElement
  text : String
[書き込み専用] エレメントのコンテンツであるテキストを受け取ります。
TextElement
 InheritedtextBlock : TextBlock
[読み取り専用] このエレメントが含まれる TextBlock です。
ContentElement
 InheritedtextBlockBeginIndex : int
[読み取り専用] このエレメントの最初の文字のテキストブロック内のインデックスです。
ContentElement
 InheritedtextRotation : String
エレメントを単位として適用される回転です。
ContentElement
 InheriteduserData : *
作成者が任意のデータをエレメントに関連付けるための方法を提供します。
ContentElement
パブリックメソッド
 メソッド定義元
  
TextElement(text:String = null, elementFormat:ElementFormat = null, eventMirror:EventDispatcher = null, textRotation:String = "rotate0")
新しい TextElement インスタンスを作成します。
TextElement
 Inherited
オブジェクトに指定されたプロパティが定義されているかどうかを示します。
Object
 Inherited
Object クラスのインスタンスが、パラメータとして指定されたオブジェクトのプロトタイプチェーン内にあるかどうかを示します。
Object
 Inherited
指定されたプロパティが存在し、列挙できるかどうかを示します。
Object
  
replaceText(beginIndex:int, endIndex:int, newText:String):void
beginIndex パラメータと endIndex パラメータで指定された文字範囲を、newText パラメータの内容に置き換えます。
TextElement
 Inherited
ループ処理に対するダイナミックプロパティの可用性を設定します。
Object
 Inherited
指定されたオブジェクトのストリング表現を返します。
Object
 Inherited
指定されたオブジェクトのプリミティブな値を返します。
Object
パブリック定数
 定数定義元
 InheritedGRAPHIC_ELEMENT : uint = 0xFDEF
[静的] テキスト内にグラフィックエレメントが存在するかどうかを示します。
ContentElement
プロパティの詳細
textプロパティ
text:String  [書き込み専用]

言語バージョン: ActionScript 3.0
ランタイムバージョン: Flash Player 10, AIR 1.5

エレメントのコンテンツであるテキストを受け取ります。

デフォルト値は null です。



実装
    public function set text(value:String):void
コンストラクタの詳細
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

新しい TextElement インスタンスを作成します。

パラメータ
text:String (default = null) — エレメントのテキストです。デフォルト値は null です。
 
elementFormat:ElementFormat (default = null) — エレメント内のテキストのエレメント形式です。デフォルト値は null です。
 
eventMirror:EventDispatcher (default = null) — このコンテンツエレメントに基づいたテキスト行に送出されるすべてのイベントのコピーを受け取る EventDispatcher オブジェクトです。 デフォルト値は null です。
 
textRotation:String (default = "rotate0") — エレメントを単位として適用される回転です。このプロパティには、flash.text.engine.TextRotation 定数を使用します。デフォルト値は、flash.text.engine.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

beginIndex パラメータと endIndex パラメータで指定された文字範囲を、newText パラメータの内容に置き換えます。beginIndexendIndex の値は、text の現在のコンテンツを参照します。

テキストを削除するには、nullnewText に渡します。

テキストを挿入するには、beginIndex および endIndex に同じ値を渡します。新しいテキストは、指定されたインデックスの前に挿入されます。

テキストを追加するには、text.lengthbeginIndex および endIndex に渡します。

すべてのテキストを設定するには、0 を beginIndex に渡し、text.lengthendIndex に渡します。

パラメータ

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);
        }
    }
}




 

 

このページに新しいコメントが追加された場合に、電子メールでの通知を希望する。 | コメントレポート

現在のページ: http://livedocs.adobe.com/flex/3_jp/langref/flash/text/engine/TextElement.html