Return to Snippet

Revision: 19652
at October 27, 2009 20:32 by trevorhartman


Updated Code
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

Revision: 19651
at October 27, 2009 20:31 by trevorhartman


Updated Code
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

Revision: 19650
at October 27, 2009 20:30 by trevorhartman


Initial Code
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

Initial URL


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

Initial Title
AS3 HTML clean up

Initial Tags
html

Initial Language
ActionScript 3