/ 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)!
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var copyHTML:String = some_value_from_a_database_or_something_containing_html; copyHTML = copyHTML.replace(/ /gm, "\n"); // fix double carriage returns copyHTML = copyHTML.replace(/’/g, "’"); // fix nasty apostrophes copyHTML = copyHTML.replace(/—/g, "—"); // fix evil en-dashes copyHTML = copyHTML.replace(/–/g, "–"); // fix abominable em-dashes var tf:TextField = new TextField(); tf.htmlText = copyHTML; // drink a beer