Skip to main content
This topic has been closed for replies.
Correct answer Jin-Huang

Thanks for the great answer! clears up alot of things for me. Now how do i loop thorugh every character for that leaf? or rather how do i know what character each "atom" is bound to? Is this correct?

while (charPosition < textLine.textBlockBeginIndex + textLine.rawTextLength) {

var atomIndex:int = textLine.getAtomIndexAtCharIndex(charPosition);

var atom:Object = new Object;
atom['char'] = _source.getText(charPosition,charPosition+1);
atom['x'] = textLine.getAtomBounds(atomIndex).x;
atom['y'] = textLine.getAtomBounds(atomIndex).y;
atom['width'] = textLine.getAtomBounds(atomIndex).width;
atom['height'] = textLine.getAtomBounds(atomIndex).height;


var range:TextRange = new TextRange(_source,charPosition,charPosition);
var format:TextLayoutFormat = _source.interactionManager.getCommonCharacterFormat(range);

atom['fontFamily'] = format.fontFamily;
atom['fontSize'] = format.fontSize;

charPosition = textLine.getAtomTextBlockEndIndex(atomIndex);
}

I seem to get one empty atom at the end of this loop.


rawTextLength : int

[read-only]        The length of the raw text in the text block that became the line,       including the U+FDEF characters representing graphic elements       and any trailing spaces, which are part of the line but not are displayed.

Your code seems good. I did not tried to get the atom of textline ago, so I can only share the experience I had.

1.textline.y give me the bottom of the textline not the top. So you need to differ textline.y from textLine.getAtomBounds(atomIndex).y;

2.When you use TLF, code like "_source.interactionManager.getCommonCharacterFormat"is not recommended.

You need to write the code as follows to skip the call of getter function when you will use _source.interactionManager many times. Because when you run "a.b", you call the "get b()" in class "a". "get b()" may be a large function and cost a lot.

var editManager:SelectionManager  = _source.interactionManager as SelectionManager;

editManager.getCommonCharacterFormat()


2 replies

Participating Frequently
June 9, 2011

This din't work all the way, for multiple lines i get the first characters in the textflow as characters for each atom.

atom['char'] = _source.getText(charPosition,charPosition+1); 

returns the absolute index for each character and not for each textline. Is there another way to get the character related to an atom?

Im guessing the format has the same issue as this. One solution would be to count every character for each textline leading up, not sure this is a stable solution though. Thanks!

Adobe Employee
June 9, 2011

Yes, they are all absolute index.

But you can get the absoluteStart of the TextLine. absoluteStart is a public variable of flashx.textlayout.compose.TextFlowLine, which is the counterpart of TextLine in TLF, include more information than TextLine.

You have two ways to get TextFlowLine:

1. firstly get the TextLine, then TextLine.userData.

2. directly get TextFlowLine by composer.findLineAtPosition()

Participating Frequently
June 15, 2011

This works greate! many thanks! i ran into another bit of wierd problem related to this now.. if i change focusedSelectionFormat in the textflow i can no longer use the command for figuring out  (seamingly random)  some character using this teqnique:

var editManager:EditManager = _source.interactionManager as EditManager;

var format:TextLayoutFormat = editManager.getCommonCharacterFormat(range);

Sometimes the _source.interactionManager returns null.

This is what i have done..

textFlow.interactionManager.focusedSelectionFormat = new SelectionFormat(0xe3e3e3,1.0,'difference');

I also tried using RichEditableText style setting wich gave me the same result.

text.setStyle('focusedTextSelectionColor', '#00FF00');

Adobe Employee
June 7, 2011

Your understanding about "i" is incorrect.

textflow.flowComposer.findLineAtPosition(i);

"i" means the cursor position, or the index, not the number of the textline.

This index can also be used to get characters and formats, for example,

FlowElement.getCharAtPosition(index);

SelectionManager.getCommonCharacterFormat(range); (Have a look at the other functions in SelectionManager. There should be a function you wanted.)

Participating Frequently
June 7, 2011

Allright, so i guess i should use something like:

source.flowComposer.getLineAt(i);

?

This is very confusing and raises even more questions for me, how do i loop through every FlowElement and isn't "getCharAtPosition" the equivilant of "findLineAtPosition" but for character? Is it posible to be getting the character boundries using SelectionManager? some example code would be highly appriciated. Thanks for the quick answer!

Adobe Employee
June 7, 2011
Allright, so i guess i should use something like:

source.flowComposer.getLineAt(i);

       Yes, this "i" means the number of the textline.

how do i loop through every FlowElement

       Usually, you loop through a textflow leaf by leaf (such as span and InlineGraphic). The text is placed onto the container leaf by leaf, right?

       TextFlow.getFirstLeaf(); leaf.getNextLeaf();

"getCharAtPosition" the equivilant of "findLineAtPosition" but for character?

       Yes!

Is it posible to be getting the character boundries using SelectionManager?

       I don't think so. TextLine is the FTE(Flash Text Engine) object. TextFlowLine is the relative object of TextLine in TLF. But there is no relative object or variable in TextFlowLine for TextLine Atom, because TLF don't need the bounds of the character. So you can only get the atomBounds though FTE calls like what you have done in your code.