开发者

Unusual problem setting newline character in spark textarea

I have Spark text area which contains the following text: "text1\ntext2\ntext3"

Text above is showing as 3 words each on separate line.

text1

text2

text3

Ok

Now i want to stylize text and add background color:

var tmp:String = textArea.text.replace("\n", '</span><br/><span backgroundColor="#B22300">');
textArea.textFlow = spark.utils.TextFlowUtil.importFromStr开发者_JAVA百科ing('<span backgroundColor="#B22300">'+tmp+'</span>');

result: it's not working. Text is displayed with background color but in 2 lines:

text1

text2 text3

So my question is: what am i doing wrong ?


in your example, you write:

text1\ntext2\text3

i'll assume you meant to write this:

text1\ntext2\ntext3

in which case i believe it's only replacing the last instance of the new line character. try using a regular expression with a global flag:

var tmp:String = textArea.text.replace(new RegExp("\\n", "g"), "</span><br/><span backgroundColor = \"#B22300\">");


Just out of curiosity, what happens when you change <br/> to <br />? That would technically be more correct and I'll wager Flash will appreciate the closing.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜