

//create a default textformat var $DefaultFmt = new TextFormat("Times New Roman",12,0x000000,false, false,false,"","","left",0,0,0,0); //create the hidden textfield _root.createTextField("$ConvTxt",-10,0,0,0,0); //initialize it var $ConvTxt = _root.$ConvTxt; $ConvTxt.visible = false; $ConvTxt.html = true; //takes an input string and format and converts it to html _global.fmtToHtml = function(txt:String,fmt:TextFormat):String { //asign text $ConvTxt.text = txt; //reset all formating $ConvTxt.setTextFormat($DefaultFmt); //apply new format $ConvTxt.setTextFormat(fmt); return $ConvTxt.htmlText; }You'll notice that before applying the TextFormat, it's first reset with a default format. This is necessary because when apply a new TextFormat, it is merged with the existing format. For example if the currently applied format had the bold property set to true, and you applied a new format without explicitly setting bold to false, the resulting format would still be bold.
This site is licensed under a
Creative Commons License