problem with getCharIndexAtPoint function
Hi
I've met a strange problem using the function; this is a simple code that works well:
package
{
import flash.display.Sprite;
import flash.events.MouseEvent;
import fl.text.TLFTextField;
import flash.text.TextFieldType;
import flash.geom.Rectangle;
import flashx.textLayout.elements.Configuration;
import flashx.textLayout.elements.TextFlow;
import flashx.textLayout.conversion.TextConverter;
import flashx.textLayout.conversion.ConversionType;
public class scrollV extends Sprite
{
private var tlf:TLFTextField = new TLFTextField;
private var str:String = "Click in this text field. Compare the "+
"difference between clicking without "+
"selecting versus clicking and selecting text.";
public function scrollV()
{
var config:Configuration = TextFlow.defaultConfiguration;
config.manageTabKey = true; // activate the tab key
addChild(tlf); tlf.width = 200;
tlf.text = str;
tlf.wordWrap = true;
tlf.type = TextFieldType.INPUT;
tlf.addEventListener(MouseEvent.CLICK, printCursorPosition);
trace(TextConverter.export(tlf.textFlow, TextConverter.TEXT_LAYOUT_FORMAT,ConversionType.STRING_TYPE) as String);
}
private function printCursorPosition(e:*):void
{
trace("char #:", tlf.caretIndex+" from:", tlf.selectionBeginIndex+" to:", tlf.selectionEndIndex);
var rett:Rectangle = tlf.getCharBoundaries(tlf.caretIndex);
trace('char pos: '+rett.x+','+rett.y);
trace('idx #: '+tlf.getCharIndexAtPoint(rett.x,rett.y));
}
}
}
In this code the getCharIndexAtPoint function work correctly; then I wanted to try the same function but using textFlow and, using the output of export trace, I have written the following code:
package
{
import flash.display.Sprite;
import flash.events.MouseEvent;
import fl.text.TLFTextField;
import flash.text.TextFieldType;
import flash.geom.Rectangle;
import flashx.textLayout.elements.Configuration;
import flashx.textLayout.elements.TextFlow;
import flashx.textLayout.conversion.TextConverter;
import flashx.textLayout.conversion.ConversionType;
import flashx.textLayout.container.ContainerController;
public class scrollV extends Sprite
{
private var tlf:TLFTextField = new TLFTextField;
private var str:String = '<TextFlow columnCount="inherit" +
'columnGap="inherit" +
'columnWidth="inherit" '+
'lineBreak="explicit" paddingBottom="inherit" +
'paddingLeft="inherit" '+
'paddingRight="inherit" paddingTop="inherit" +
'renderingMode="normal" '+
'verticalAlign="inherit" +
'whiteSpaceCollapse="preserve" '+
'xmlns="http://ns.adobe.com/textLayout/2008"> '+
'<p><span renderingMode="inherit">'+
'Click in this text field. Compare the difference '+
'between clicking without selecting '+
'versus clicking and selecting text. '+
'</span></p>'+
'</TextFlow>';
public function scrollV()
{
var config:Configuration = TextFlow.defaultConfiguration;
config.manageTabKey = true; // activate the tab key
addChild(tlf); tlf.width = 200;
tlf.textFlow= TextConverter.importToFlow(str,TextConverter.TEXT_LAYOUT_FORMAT);
var control:ContainerController = new ContainerController(tlf);
tlf.textFlow.flowComposer.addController(control);
tlf.textFlow.flowComposer.compose();
tlf.textFlow.flowComposer.updateAllControllers();
tlf.wordWrap = true;
tlf.type = TextFieldType.INPUT;
tlf.addEventListener(MouseEvent.CLICK, printCursorPosition);
trace(TextConverter.export(tlf.textFlow, TextConverter.TEXT_LAYOUT_FORMAT,ConversionType.STRING_TYPE) as String);
}
private function printCursorPosition(e:*):void
{
trace("char #:", tlf.caretIndex+" from:", tlf.selectionBeginIndex+" to:", tlf.selectionEndIndex);
var rett:Rectangle = tlf.getCharBoundaries(tlf.caretIndex);
trace('pos: '+rett.x+','+rett.y);
trace('idx #: '+tlf.getCharIndexAtPoint(rett.x,rett.y));
}
}
}
in this code the getCharIndexAtPoint function gives the error #1009:Cannot access a property or method of a null object reference.
Does someone know how to tell me where the error is in this code?
thank for all.
