| Pacote | flashx.textLayout.events |
| Classe | public class CompositionCompleteEvent |
| Herança | CompositionCompleteEvent Event Object |
| Versão da linguagem: | ActionScript 3.0 |
| Versões de runtime: | Flash Player 10, AIR 1.5 |
Três métodos principais que despacham este evento são compose(), updateToController() e updateAllControllers(). Todos os três destes métodos estão na classe StandardFlowComposer.
Nota: se o evento for despachado pelo método updateAllControllers(), não chame updateAllControllers() novamente na sua função de controlador de eventos. Essa chamada seria uma chamada recursiva porque o método updateAllControllers() executa ambos passos de exibição e composição. O updateAllControllers() despacha este evento depois que a composição for concluída, mas antes que a passo etapa de exibição seja executada. O mesmo raciocínio se aplica ao método updateToController().
Elementos da API relacionados
| Propriedade | Definido por | ||
|---|---|---|---|
![]() | bubbles : Boolean [somente leitura]
Indica se um evento é do tipo bubbling. | Event | |
![]() | cancelable : Boolean [somente leitura]
Indica se o comportamento associado ao evento pode ser impedido. | Event | |
| compositionLength : int
Número de caracteres compostos. | CompositionCompleteEvent | ||
| compositionStart : int
O local de início do intervalo de texto afetado pela composição, expresso como um índice dentro do fluxo de texto. | CompositionCompleteEvent | ||
![]() | constructor : Object
Uma referência ao objeto de classe ou à função de construtor de uma determinada ocorrência de objeto. | Object | |
![]() | currentTarget : Object [somente leitura]
O objeto que está processando ativamente o objeto Event com um ouvinte de evento. | Event | |
![]() | eventPhase : uint [somente leitura]
A fase atual no fluxo de eventos. | Event | |
![]() | target : Object [somente leitura]
O destino de evento. | Event | |
| textFlow : flashx.textLayout.elements:TextFlow
TextFlow em que a composição foi concluída. | CompositionCompleteEvent | ||
![]() | type : String [somente leitura]
O tipo de evento. | Event | |
| Método | Definido por | ||
|---|---|---|---|
CompositionCompleteEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, textFlow:flashx.textLayout.elements:TextFlow = null, compositionStart:int = 0, compositionLength:int = 0) Construtor
| CompositionCompleteEvent | ||
![]() |
Duplica uma ocorrência de uma subclasse Event. | Event | |
![]() |
Uma função de utilitário para implementar o método toString() em classes ActionScript 3.0 Event personalizadas. | Event | |
![]() |
Indica se um objeto tem uma propriedade especificada definida. | Object | |
![]() |
Verifica se o método preventDefault() foi chamado no evento. | Event | |
![]() |
Indica se uma ocorrência da classe Object está na cadeia de protótipos do objeto especificado como o parâmetro. | Object | |
![]() |
Cancela um comportamento padrão de evento se esse comportamento puder ser cancelado. | Event | |
![]() |
Indica se a propriedade especificada existe e é enumerável. | Object | |
![]() |
Define a disponibilidade de uma propriedade dinâmica para operações de repetição. | Object | |
![]() |
Impede o processamento de qualquer ouvinte de evento no nó atual e qualquer nó subsequente no fluxo de eventos. | Event | |
![]() |
Impede o processamento de algum ouvinte de evento em nós subsequentes ao nó atual no fluxo de eventos. | Event | |
![]() |
Retorna a representação da string deste objeto, formatado segundo as convenções específicas para a localidade. | Object | |
![]() |
Retorna uma string que contém todas as propriedades do objeto Event. | Event | |
![]() |
Retorna o valor primitivo do objeto especificado. | Object | |
| Constante | Definido por | ||
|---|---|---|---|
| COMPOSITION_COMPLETE : String = "compositionComplete" [estático]
Define o valor da propriedade type de um objeto de evento compositionComplete
| CompositionCompleteEvent | ||
compositionLength | propriedade |
compositionStart | propriedade |
compositionStart:int| Versão da linguagem: | ActionScript 3.0 |
| Versões de runtime: | Flash Player 10, AIR 1.5 |
O local de início do intervalo de texto afetado pela composição, expresso como um índice dentro do fluxo de texto.
Implementação
public function get compositionStart():int public function set compositionStart(value:int):voidtextFlow | propriedade |
textFlow:flashx.textLayout.elements:TextFlow| Versão da linguagem: | ActionScript 3.0 |
| Versões de runtime: | Flash Player 10, AIR 1.5 |
TextFlow em que a composição foi concluída.
Implementação
public function get textFlow():flashx.textLayout.elements:TextFlow public function set textFlow(value:flashx.textLayout.elements:TextFlow):voidCompositionCompleteEvent | () | Construtor |
public function CompositionCompleteEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, textFlow:flashx.textLayout.elements:TextFlow = null, compositionStart:int = 0, compositionLength:int = 0)| Versão da linguagem: | ActionScript 3.0 |
| Versões de runtime: | Flash Player 10, AIR 1.5 |
Construtor
Parâmetrostype:String — tipo de evento - use a propriedade estática COMPOSITION_COMPLETE.
| |
bubbles:Boolean (default = false) — Indica se um evento é do tipo bubbling. Este evento não realiza bubbling.
| |
cancelable:Boolean (default = false) — Indica se o comportamento associado ao evento pode ser impedido. Este evento não pode ser cancelado.
| |
textFlow:flashx.textLayout.elements:TextFlow (default = null) — O TextFlow que foi composto
| |
compositionStart:int (default = 0) — início da composição, em termos de um índice dentro do fluxo de texto.
| |
compositionLength:int (default = 0) — número de caracteres compostos
|
COMPOSITION_COMPLETE | Constante |
public static const COMPOSITION_COMPLETE:String = "compositionComplete"| Versão da linguagem: | ActionScript 3.0 |
| Versões de runtime: | Flash Player 10, AIR 1.5 |
Define o valor da propriedade type de um objeto de evento compositionComplete
Este exemplo mostra como usar a classe CompositionCompleteEvent para destacar uma palavra específica em umTextFlow. Esta técnica representa uma alternativa para configurar a propriedade TextLayoutFormat.backgroundColor antes do texto ser composto.
O método compositionCompleteHandler() é executado depois que o método updateAllControllers() inicia a execução compondo o texto, mas antes updateAllControllers() conclui a execução atualizando a lista de exibição. Isso permite que o método gerenciador de eventos desenhe o realce da palavra "shall" antes de updateAllControllers() atualizar a lista de exibição.
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);
}
}
}
Wed Jun 13 2018, 11:10 AM Z
Ocultar propriedades públicas herdadas
Mostrar propriedades públicas herdadas