AS3:获取 x 和文本字段中匹配字符串的 y 值
我在 Flash 中有一个文本字段,其中包含一个(显然)文本块。
我想要做的是对返回 x & 的文本字段的内容执行搜索。 y 坐标和宽度和宽度找到的文本的高度
。结果将用于将视觉元素放置在文本框的该部分上。
例如:
var pattern:RegExp = /\d+/g;
var found:Array = box.text.match(pattern);
var i:String;
for each(i in found)
{
/**
* Find the x, y, width, height of the matched text in the text field
* Use result to place transparent yellow box around text
*/
}
视觉上应该产生如下结果:
I have a text field within Flash that contains a block of (obviously) text.
What I want to do is perform a search on the content of the text field that returns the x & y
coordiante and the width & height
of the found text. The result will be used to place a visual element over that portion of the text box.
For example:
var pattern:RegExp = /\d+/g;
var found:Array = box.text.match(pattern);
var i:String;
for each(i in found)
{
/**
* Find the x, y, width, height of the matched text in the text field
* Use result to place transparent yellow box around text
*/
}
Which visually should result in something like:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能需要使用 TextField 类的 getCharBoundaries 方法,该方法接受字符索引并返回 Rectangle 对象。
据我所知,您的
match
方法返回字符串本身,因此首先您可能需要使用 String 类的indexOf
方法,找到所有字符索引,通过将它们传递给getCharBoundaries
方法,然后根据该输出绘制一些矩形。这里有一些参考。
祝你好运!
You would want to make use of the TextField class's
getCharBoundaries
method, which accepts character indexes and returns a Rectangle object.As far as I know, your
match
method returns the strings themselves, so first you'll probably need to use the String class'sindexOf
method, find all your character indexes, pass them to thegetCharBoundaries
method, then draw some rectangles based on that output.Here's some reference.
Good luck!