Termos
Termos

Reputation: 694

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.importFromString('<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 ?

Upvotes: 0

Views: 744

Answers (2)

cwallenpoole
cwallenpoole

Reputation: 81988

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.

Upvotes: 0

Chunky Chunk
Chunky Chunk

Reputation: 17217

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\">");

Upvotes: 1

Related Questions