Posted By

trevorhartman on 10/27/09


Tagged

parse html TextField as3


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

tspitzr


AS3 HTML clean up


 / Published in: ActionScript 3
 

AS3 does some weird things with HTML. Here are a few ways to handle common problems. The worst offender that many people encounter is double carriage returns. Regex those nasty buggers into oblivion (aka \n)!

  1. var copyHTML:String = some_value_from_a_database_or_something_containing_html;
  2. copyHTML = copyHTML.replace(/
  3. /gm, "\n"); // fix double carriage returns
  4. copyHTML = copyHTML.replace(//g, "’"); // fix nasty apostrophes
  5. copyHTML = copyHTML.replace(//g, "—"); // fix evil en-dashes
  6. copyHTML = copyHTML.replace(//g, "–"); // fix abominable em-dashes
  7.  
  8.  
  9. var tf:TextField = new TextField();
  10. tf.htmlText = copyHTML; // drink a beer

Report this snippet  

You need to login to post a comment.