基于父项的文本字段的字符边界 [英] Character boundaries of text field based on parent
问题描述
这是一个示例屏幕截图:
正常状态会是这样的:
这样我就可以根据文本字段找到每个字符的边界,但是我需要基于容器:
var rect:Rectangle = new Rectangle();
for(var i:int = 0; i< textField.length; i ++){
rect = textField.getCharBoundaries(i);
$ / code>
有没有人有这方面的经验? $ b
我相信你必须利用Point转换。 c $ c> var rect:Rectangle = new Rectangle();
for(var i:int = 0; i< textField.length; i ++){
rect = textField.getCharBoundaries(i);
var globalTopLeft:Point = textField.localToGlobal(rect.topLeft);
var globalBottomRight:Point = textField.localToGlobal(rect.bottomRight);
var containerTopLeft:Point = container.globalToLocal(globalTopLeft);
var containerBottomRight:Point = container.globalToLocal(globalBottomRight);
RECT =新的Rectangle(containerTopLeft.x,containerTopLeft.y,containerBottomRight.x-containerTopLeft.x,containerBottomRight.y-containerTopLeft.y)
}
I have a text field inside a container. I'm wondering is it possible to find the boundaries of each character based on the container and not the text field.
Here is a sample screen shot:
And normal state would be like this: With this I can find the bounds of each character based on text field, But I need it based on the container:
var rect:Rectangle = new Rectangle();
for (var i:int = 0; i < textField.length; i++){
rect = textField.getCharBoundaries(i);
}
Is there anybody whom has an experience on this?
I believe you have to make use of Point conversions.
var rect:Rectangle = new Rectangle();
for (var i:int = 0; i < textField.length; i++){
rect = textField.getCharBoundaries(i);
var globalTopLeft:Point = textField.localToGlobal(rect.topLeft);
var globalBottomRight:Point = textField.localToGlobal(rect.bottomRight);
var containerTopLeft:Point = container.globalToLocal(globalTopLeft);
var containerBottomRight:Point = container.globalToLocal(globalBottomRight);
rect = new Rectangle(containerTopLeft.x,containerTopLeft.y,containerBottomRight.x-containerTopLeft.x,containerBottomRight.y-containerTopLeft.y)
}
这篇关于基于父项的文本字段的字符边界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!