패키지 | flashx.textLayout.events |
클래스 | public class CompositionCompleteEvent |
상속 | CompositionCompleteEvent ![]() ![]() |
언어 버전: | ActionScript 3.0 |
런타임 버전: | Flash Player 10, AIR 1.5 |
이 이벤트를 전달하는 세 개의 기본 메서드는 compose()
, updateToController()
및 updateAllControllers()
입니다. 이 세 메서드 모두 StandardFlowComposer 클래스에 포함되어 있습니다.
참고:
updateAllControllers()
메서드로 이벤트를 전달하는 경우 이벤트 핸들러 함수에서 updateAllControllers()
를 다시 호출하지 마십시오. 다시 호출하는 경우 updateAllControllers()
메서드가 구성과 표시 단계를 모두 실행하기 때문에 순환 호출이 됩니다. updateAllControllers()
는 구성을 완료한 후 표시 단계를 실행하기 전에 이 이벤트를 전달합니다. updateToController()
메서드의 경우도 마찬가지입니다.
관련 API 요소
속성 | 정의 주체 | ||
---|---|---|---|
![]() | bubbles : Boolean [읽기 전용]
이벤트가 버블링 이벤트인지 여부를 나타냅니다. | Event | |
![]() | cancelable : Boolean [읽기 전용]
해당 이벤트와 연관된 비헤이비어를 차단할 수 있는지 여부를 나타냅니다. | Event | |
compositionLength : int
컴포지션된 문자의 수입니다. | CompositionCompleteEvent | ||
compositionStart : int
컴포지션의 영향을 받는 텍스트 범위의 시작 위치이며 텍스트 흐름에 대한 인덱스로 표시됩니다. | CompositionCompleteEvent | ||
![]() | constructor : Object
지정된 객체 인스턴스의 클래스 객체 또는 생성자 함수에 대한 참조입니다. | Object | |
![]() | currentTarget : Object [읽기 전용]
이벤트 리스너를 통해 Event 객체를 처리하고 있는 객체입니다. | Event | |
![]() | eventPhase : uint [읽기 전용]
이벤트 흐름에서 현재 단계입니다. | Event | |
![]() | target : Object [읽기 전용]
이벤트 대상입니다. | Event | |
textFlow : flashx.textLayout.elements:TextFlow
구성이 완료된 TextFlow입니다. | CompositionCompleteEvent | ||
![]() | type : String [읽기 전용]
이벤트 유형입니다. | Event |
메서드 | 정의 주체 | ||
---|---|---|---|
CompositionCompleteEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, textFlow:flashx.textLayout.elements:TextFlow = null, compositionStart:int = 0, compositionLength:int = 0) 생성자
| CompositionCompleteEvent | ||
![]() |
Event 하위 클래스의 인스턴스를 복제합니다. | Event | |
![]() |
사용자 정의 ActionScript 3.0 Event 클래스에서 toString() 메서드를 구현하기 위한 유틸리티 함수입니다. | Event | |
![]() |
지정된 속성이 객체에 정의되어 있는지 여부를 나타냅니다. | Object | |
![]() |
이벤트에서 preventDefault() 메서드가 호출되었는지 여부를 확인합니다. | Event | |
![]() |
Object 클래스의 인스턴스가 매개 변수로 지정된 객체의 프로토타입 체인에 있는지 여부를 나타냅니다. | Object | |
![]() |
이벤트의 기본 비헤이비어를 취소할 수 있는 경우, 그 비헤이비어를 취소합니다. | Event | |
![]() |
지정된 속성이 존재하고 열거 가능한지 여부를 나타냅니다. | Object | |
![]() |
루프 작업에서 동적 속성을 사용할 수 있는지 여부를 설정합니다. | Object | |
![]() |
이벤트 흐름에서 현재 노드 및 그 후속 노드에 있는 모든 이벤트 리스너가 처리되지 않도록 합니다. | Event | |
![]() |
이벤트 흐름에서 현재 노드의 후속 노드에 있는 모든 이벤트 리스너가 처리되지 않도록 합니다. | Event | |
![]() |
로캘별 규칙에 따라 서식이 지정된 이 객체의 문자열 표현을 반환합니다. | Object | |
![]() |
Event 객체의 속성이 모두 포함된 문자열을 반환합니다. | Event | |
![]() |
지정된 객체의 프리미티브 값을 반환합니다. | Object |
상수 | 정의 주체 | ||
---|---|---|---|
COMPOSITION_COMPLETE : String = "compositionComplete" [정적]
compositionComplete 이벤트 객체의 type 속성 값을 정의합니다
| CompositionCompleteEvent |
compositionLength | 속성 |
compositionStart | 속성 |
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 클래스를 사용하여 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); } } }
Tue Jun 12 2018, 03:17 PM Z