2011-07-13 25 views
3

我在Flash中有一個文本字段,其中包含一個(明顯)文本塊。AS3:獲取文本字段中匹配字符串的x和y值

我想要做的是對文本字段的內容進行搜索,該文本字段返回找到的文本的x & y coordiante和width & height。結果將用於在文本框的該部分上放置可視元素。

例如:

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 
    */ 
} 

在視覺上應該導致這樣的:

enter image description here

+0

有趣的問題,我總是想知道如何做到這一點! –

回答

4

你會想利用TextField類的​​方法,它接受字符指數和收益一個Rectangle對象。

據我所知,你的match方法返回字符串本身,所以首先你可能需要使用String類的indexOf方法,找到所有你的性格指標,它們傳遞到​​方法,然後得出一些矩形基於那個輸出。

Here's some reference

祝你好運!

+0

啊,非常好。我使用match()來解析正則表達式(在這種情況下查找數字),匹配的將使用indexOf()。謝謝。 – Marty

+0

感謝您的支持。我以爲我必須要做數學或數字。很高興這存在。 –

相關問題