Actionscript 3 TextField renders excessive line breaks

11 work  |   August 10, 2007  |     895

Hi all,

I was working on a project for musicnation.com, their EPK. I had to render text in a textfield that was coming from an XML feed, text that is entered by users. It can be filled with different types of line feeds, notable the:

\n = linux
\r = mac (prior to macos being based on freebsd I guess)
\r\n = the damned pc linefeed.

The TextField object in Flash seems to render both \r and \n as linefeeds. Therefore I was getting way too many linefeeds in my rendered text.

Here is my solution:

Tada! _text is of type String. The /g is VERY important at the end of the declaration of the RegExp, it means it will replace ALL instances. If you do not put /g it wont.

🙂

Martin

Comments
  • May 13, 2008 at 10:31 pm

    Kyle Ward

    Thanks for this mate!

  • October 22, 2008 at 1:54 am

    Ian

    Awesome, this was driving me mental !

  • November 12, 2008 at 8:48 am

    enrico

    thanks for this tip, very useful 🙂

  • February 7, 2009 at 2:31 pm

    Siegbert

    Juhuu!

  • June 6, 2009 at 12:49 pm

    sam

    thank you this was a great quick solution!

  • August 20, 2009 at 2:04 am

    Brandon

    Thanks!

    It also works to get rid of line breaks!

  • October 21, 2009 at 10:21 am

    Nicolas Baptista

    Very useful tip.

    Thanks for sharing! =)

  • December 7, 2009 at 8:07 am

    Erwan

    thanks for the tip!
    RegExp are so usefull in many langages, but very tricky to implement…

  • December 15, 2009 at 6:39 am

    Andy

    You really saved my day! Great!!

  • May 25, 2010 at 3:25 am

    McAlyster

    Thanx = )

  • January 14, 2014 at 5:56 am

    trupti

    Thanks, works great!

Leave a Reply