Adobe® Flash® Platform 用 ActionScript® 3.0 リファレンスガイド
ホーム  |  パッケージおよびクラスリストの非表示 |  パッケージ  |  クラス  |  新機能  |  索引  |  付録  |  英語で表示される理由
フィルター: サーバーからデータを取得しています...
サーバーからデータを取得しています...
flashx.textLayout.events 

CompositionCompleteEvent  - AS3

パッケージflashx.textLayout.events
クラスpublic class CompositionCompleteEvent
継承CompositionCompleteEvent Inheritance Event Inheritance Object

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

このイベントは、作成操作の完了後に TextFlow インスタンスによって送出されます。各テキストコンテナには、入力と表示の 2 つのステータスがあります。このイベントは、作成段階が終了したことを通知します。これにより、テキストを表示する前に、コンテナに必要および適切な変更を加えることができます。例えば、このイベントを使用してテキストフロー内の特定の単語または文字にハイライトを追加してから、そのテキストを表示できます。

このイベントを送出する主なメソッドは、compose()updateToController() および updateAllControllers() です。これら 3 つのメソッドはすべて StandardFlowComposer クラスにあります。

注意: updateAllControllers() メソッドから送出されるイベントについては、イベントハンドラー関数で updateAllControllers() を再び呼び出さないようにしてください。updateAllControllers() メソッドでは作成と表示の両ステップを実行するので、このような呼び出しは再帰的な呼び出しになります。updateAllControllers() は、作成の終了後、表示ステップの実行前にこのイベントを送出します。この論理は updateToController() メソッドにも当てはまります。

例を表示

関連する API エレメント



パブリックプロパティ
 プロパティ定義元
 Inheritedbubbles : Boolean
[読み取り専用] イベントがバブリングイベントかどうかを示します。
Event
 Inheritedcancelable : Boolean
[読み取り専用] イベントに関連付けられた動作を回避できるかどうかを示します。
Event
  compositionLength : int
作成される文字数です。
CompositionCompleteEvent
  compositionStart : int
作成の影響を受けるテキスト範囲の開始位置です。テキストフローへのインデックスとして示されます。
CompositionCompleteEvent
 Inheritedconstructor : Object
指定されたオブジェクトインスタンスのクラスオブジェクトまたはコンストラクター関数への参照です。
Object
 InheritedcurrentTarget : Object
[読み取り専用] イベントリスナーで Event オブジェクトをアクティブに処理しているオブジェクトです。
Event
 InheritedeventPhase : uint
[読み取り専用] イベントフローの現在の段階です。
Event
 Inheritedtarget : Object
[読み取り専用] イベントターゲットです。
Event
  textFlow : flashx.textLayout.elements:TextFlow
作成が終了した TextFlow です。
CompositionCompleteEvent
 Inheritedtype : String
[読み取り専用] イベントのタイプです。
Event
パブリックメソッド
 メソッド定義元
  
CompositionCompleteEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, textFlow:flashx.textLayout.elements:TextFlow = null, compositionStart:int = 0, compositionLength:int = 0)
コンストラクター
CompositionCompleteEvent
 Inherited
Event サブクラスのインスタンスを複製します。
Event
 Inherited
formatToString(className:String, ... arguments):String
カスタム ActionScript 3.0 Event クラスに toString() メソッドを実装するためのユーティリティ関数です。
Event
 Inherited
オブジェクトに指定されたプロパティが定義されているかどうかを示します。
Object
 Inherited
イベントで preventDefault() メソッドが呼び出されたかどうかを確認します。
Event
 Inherited
Object クラスのインスタンスが、パラメーターとして指定されたオブジェクトのプロトタイプチェーン内にあるかどうかを示します。
Object
 Inherited
イベントのデフォルト動作をキャンセルできる場合に、その動作をキャンセルします。
Event
 Inherited
指定されたプロパティが存在し、列挙できるかどうかを示します。
Object
 Inherited
ループ処理に対するダイナミックプロパティの可用性を設定します。
Object
 Inherited
イベントフローの現在のノードおよび後続するノードで、イベントリスナーが処理されないようにします。
Event
 Inherited
イベントフローの現在のノードに後続するノードで、イベントリスナーが処理されないようにします。
Event
 Inherited
ロケール固有の規則に従って書式設定された、このオブジェクトのストリング表現を返します。
Object
 Inherited
Event オブジェクトのすべてのプロパティを含むストリングを返します。
Event
 Inherited
指定されたオブジェクトのプリミティブな値を返します。
Object
パブリック定数
 定数定義元
  COMPOSITION_COMPLETE : String = "compositionComplete"
[静的] compositionComplete イベントオブジェクトの type プロパティ値を定義します
CompositionCompleteEvent
プロパティの詳細

compositionLength

プロパティ
compositionLength:int

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

作成される文字数です。



実装
    public function get compositionLength():int
    public function set compositionLength(value:int):void

compositionStart

プロパティ 
compositionStart:int

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

作成の影響を受けるテキスト範囲の開始位置です。テキストフローへのインデックスとして示されます。



実装
    public function get compositionStart():int
    public function set compositionStart(value:int):void

textFlow

プロパティ 
textFlow:flashx.textLayout.elements:TextFlow

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

作成が終了した TextFlow です。



実装
    public function get textFlow():flashx.textLayout.elements:TextFlow
    public function set textFlow(value:flashx.textLayout.elements:TextFlow):void
コンストラクターの詳細

CompositionCompleteEvent

()コンストラクター
public function CompositionCompleteEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, textFlow:flashx.textLayout.elements:TextFlow = null, compositionStart:int = 0, compositionLength:int = 0)

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

コンストラクター

パラメーター
type:String — イベントタイプ - 静的プロパティ COMPOSITION_COMPLETE を使用します。
 
bubbles:Boolean (default = false) — イベントがバブリングイベントかどうかを示します。このイベントではバブリングを実行できません。
 
cancelable:Boolean (default = false) — イベントに関連付けられた動作を回避できるかどうかを示します。このイベントはキャンセルできません。
 
textFlow:flashx.textLayout.elements:TextFlow (default = null) — 作成された TextFlow
 
compositionStart:int (default = 0) — 作成の開始。テキストフローへのインデックスとして示されます。
 
compositionLength:int (default = 0) — 作成される文字の長さです
定数の詳細

COMPOSITION_COMPLETE

定数
public static const COMPOSITION_COMPLETE:String = "compositionComplete"

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

compositionComplete イベントオブジェクトの type プロパティ値を定義します

CompositionCompleteEvent_example.as

この例は、CompositionCompleteEvent クラスを使用して TextFlow 内の特定の単語をハイライトする例を示しています。ここでは、テキスト作成前に TextLayoutFormat.backgroundColor プロパティを設定する代わりとなる方法を説明しています。

compositionCompleteHandler() メソッドが実行されるタイミングは、テキスト作成による updateAllControllers() の実行開始から、表示リストの更新による updateAllControllers() の実行完了までの間です。これにより、updateAllControllers() が表示リストを更新する前に、イベントハンドラーメソッドによって単語「shall」にハイライトを追加できます。

package flashx.textLayout.events.examples
{
    import flash.display.Graphics;
    import flash.display.Sprite;
    import flash.geom.Rectangle;
    import flash.text.engine.TextLine;
    
    import flashx.textLayout.compose.StandardFlowComposer;
    import flashx.textLayout.compose.TextFlowLine;
    import flashx.textLayout.container.ContainerController;
    import flashx.textLayout.conversion.TextConverter;
    import flashx.textLayout.elements.FlowLeafElement;
    import flashx.textLayout.elements.ParagraphElement;
    import flashx.textLayout.elements.TextFlow;
    import flashx.textLayout.events.CompositionCompleteEvent;

    public class CompositionCompleteEvent_example extends Sprite
    {
        private var wordToHighlight:String = "shall";
        private var poemContainer:Sprite;
        private var txtFlow:TextFlow;
        private var controller:ContainerController;
        private const poem:String = "Sonnet 18\n" +
        "Shall I compare thee to a summer's day?\n" +
        "Thou art more lovely and more temperate:\n" +
        "Rough winds do shake the darling buds of May,\n" +
        "And summer's lease hath all too short a date:\n" +
        "Sometime too hot the eye of heaven shines,\n" +
        "And often is his gold complexion dimmed,\n" +
        "And every fair from fair sometime declines,\n" +
        "By chance, or nature's changing course untrimmed:\n" +
        "But thy eternal summer shall not fade,\n" +
        "Nor lose possession of that fair thou ow'st,\n" +
        "Nor shall death brag thou wand'rest in his shade,\n" +
        "When in eternal lines to time thou grow'st,\n" +
        "So long as men can breathe or eyes can see,\n" +
        "So long lives this, and this gives life to thee.\n" +
        "William Shakespeare\n";
        
        public function CompositionCompleteEvent_example()
        {
                 poemContainer = new Sprite();
                 txtFlow = new TextFlow();
                            
            poemContainer.x = 30;
            poemContainer.y = 30;
            this.stage.addChild( poemContainer );
            
            controller = new ContainerController(poemContainer, 300, 230);
            controller.verticalScrollPolicy = flashx.textLayout.container.ScrollPolicy.OFF;
            txtFlow = TextConverter.importToFlow( poem, TextConverter.PLAIN_TEXT_FORMAT );
            txtFlow.flowComposer = new StandardFlowComposer();

            txtFlow.addEventListener(CompositionCompleteEvent.COMPOSITION_COMPLETE, compositionCompleteHandler);
            txtFlow.flowComposer.addController( controller );

            txtFlow.flowComposer.updateAllControllers();
        }
        
        private function compositionCompleteHandler(event:CompositionCompleteEvent):void {
            if (event.textFlow == txtFlow) {
                checkForMatchingWord();
            }
        }
        
        private function checkForMatchingWord():void {
            var currentLeaf:FlowLeafElement = txtFlow.getFirstLeaf();
            var currentParagraph:ParagraphElement = currentLeaf ? currentLeaf.getParagraph() : null;
            
            while (currentParagraph) { // iterate over all paragraphs in the text flow
                var paraStart:uint = currentParagraph.getAbsoluteStart();
                var currWordBoundary:int = 0;
                var nextWordBoundary:int = 0;
                var pattern:RegExp = new RegExp(wordToHighlight, "i");
                
                while (true) { // iterate over letters in a word
                    nextWordBoundary = currentParagraph.findNextWordBoundary(currWordBoundary);
                    if (nextWordBoundary == currWordBoundary) {
                        break; // end of paragraph; break of inner while loop
                    }
                    var word:String = '';
                    var indexInLeaf:int = currWordBoundary + paraStart - currentLeaf.getAbsoluteStart();
                    var wordLen:uint = nextWordBoundary - currWordBoundary; 

                    while (true){ // traverse consecutive leaf elements looking for 'wordLen' characters
                                                        
                        // Take as many characters from the current leaf as possible to meet the quota of 'wordLen'
                        var consumeCount:uint = indexInLeaf + wordLen <= currentLeaf.textLength ? wordLen : currentLeaf.textLength - indexInLeaf; 
                        word += currentLeaf.text.substr (indexInLeaf, consumeCount);
                                                                        
                        wordLen -= consumeCount;
                        if (!wordLen)
                            break;
                            
                        // Quota not met; move to the next leaf
                        // Also reset the index where the next leaf will be scanned
                        currentLeaf = currentLeaf.getNextLeaf();
                        indexInLeaf = 0;
                    }
                    if (pattern.test(word)) {                                    
                        highlightWord(currWordBoundary, nextWordBoundary, word, paraStart);
                    }
                    currWordBoundary = nextWordBoundary;
                }
                                        
                // At this point, currentLeaf is the last leaf in currentParagraph. Move to the next paragraph.
                currentLeaf = currentLeaf.getNextLeaf();
                currentParagraph = currentLeaf ? currentLeaf.getParagraph() : null;                    
            }
        }
        
        private function highlightWord(begin:int, end:int, word:String, paraStart:int):void {
            
            var absoluteBegin:int = paraStart + begin;
            var absoluteEnd:int = paraStart + end;
            
            var startTextFlowLineIndex:int = txtFlow.flowComposer.findLineIndexAtPosition(absoluteBegin);
            var endTextFlowLineIndex:int = txtFlow.flowComposer.findLineIndexAtPosition(absoluteEnd);
            var txtFlowLine:TextFlowLine = txtFlow.flowComposer.getLineAt(startTextFlowLineIndex);
            var txtLine:TextLine = txtFlowLine.getTextLine();
            
            // get the bounds of the first and last Atom of the textLine
            var startbounds:Rectangle = txtLine.getAtomBounds(txtLine.getAtomIndexAtCharIndex(begin));
            var endbounds:Rectangle = txtLine.getAtomBounds(txtLine.getAtomIndexAtCharIndex(end));
            
            var box:Sprite = new Sprite();
            var g:Graphics = box.graphics;
            
            g.lineStyle(1, 0xFFFF00, 0.5); // set line style
            g.beginFill(0xFFFF00, 0.3); // set fill style
            // draw a rectangle around the specified boundaries
            g.drawRect(startbounds.left, startbounds.top, (endbounds.x - startbounds.x), startbounds.height);
            txtLine.addChild(box);
        }
    }
}






[ X ]英語で表示される理由
ActionScript 3.0 リファレンスガイドのコンテンツが英語で表示されます。

ActionScript 3.0 リファレンスガイドのすべての部分がすべての言語に翻訳されているわけではありません。言語エレメントが翻訳されていない場合、そのエレメントは英語で表示されます。例えば、ga.controls.HelpBox クラスはどの言語にも訳されていません。このため、リファレンスガイドの日本語バージョンでは、ga.controls.HelpBox クラスは英語で表示されます。