AS3 HTML clean up


/ Published in: ActionScript 3
Save to your folder(s)

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)!


Copy this code and paste it in your HTML
  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


Comments


You need to login to view comments.