getAtomIndexAtCharIndex Fails?
I am looking for the bounding box around a string. I know that the string exists on a given line, i checked using TextLine.textBlock.content.text.
here is what I am doing
var tokens:Array = editor.text.split(myPattern); //myPatter is a RegExp,
//editor is a RichEditableText
var pos:int = 0;
for (var i:int=0;i<tokens.length-1;i++)
{
var t:String = tokens;
pos += t.length;
var span:SpanElement = editor.textFlow.findLeaf(pos) as SpanElement;
var relativePosition:int = pos - span.getAbsoluteStart();
//var length:int = pos+searchInput.text.length;
var bbox:Rectangle = spanBBox(span,pos,relativePosition,search.length);
/// the rectangle is then used to place sprites etc,,,
pos += searchInput.text.length; // searchInput is TextInpu
}
private function spanBBox(abs:int,rel:int,len:int):Rectangle
{
var line:TextFlowLine = editor.textFlow.flowComposer.findLineAtPosition(abs);
var textLine:TextLine = line.getTextLine(true);
if(textLine.textBlock.content.text.substring(rel,rel+len) != searchInput.text)
{
//this does happen, yet the line does contain the searchInput!
rel = textLine.textBlock.content.text.indexOf(searchInput.text);
}
var atomIndex1:int = textLine.getAtomIndexAtCharIndex(rel);
var atomIndex2:int = textLine.getAtomIndexAtCharIndex(rel+len);
var r1:Rectangle = textLine.getBounds(editor);
var bbox1:Rectangle = textLine.getAtomBounds(atomIndex1);
var bbox2:Rectangle = textLine.getAtomBounds(atomIndex2);
bbox1.y = r1.y; bbox1.height = r1.height; bbox1.width = bbox2.x - bbox1.x;
bbox1.x += textLine.x;
return bbox1;
}
50% of the time atomIndex1,2 are -1. Any clues?
Thank you
Raed
