开发者

Flex 3 setSelection with htmlText

In Adobe Flex 3, this causes problems.

textArea.se开发者_如何学JAVAtSelection( textArea.htmlText.indexOf( 'testString' ), textArea.htmlText.indexOf( 'testString' ) + 10 );

This puts the cursor in the wrong place, because indexOf takes into account the HTML tags, but setSelection does not.

Anyone know how to do this? A simple way is a /<[^>]*>/g regular expression, but this doesn't do the job every time.

Help please!

Andrew


Try this instead:

textArea.setSelection( textArea.text.indexOf( 'testString' ), textArea.text.indexOf( 'testString' ) + 10 );

By using the 'text' property instead of 'htmlText', you're removing the html tags. Also, I wouldn't use 2 index searches, it's not efficient. Try this:

var string:String = 'testString';
var index:int = textArea.text.indexOf(string);
textArea.setSelection(index, index + string.length);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜