OK,
I have given up messing with stylesheets, trying display: block, inline, different ways of formatting the XML, messing with XML.ignoreWhiteSpace, and XML.prettyPrinting etc.
I went down the route of encodeURI, using a RegExp to strip out all tabs, linefeeds and carriage returns. This now gives consistent results for all situations, even embedded and none embedded fonts.
e.g.
_text:String = TEXT FROM XML, HTML TEXT etc
var st:String = encodeURI(_text);
var pattern:RegExp = /(%09)+|(%0A)+|(%0D)+/g;
st = st.replace(pattern, "");
st = decodeURI(st);
YOUTEXTFIELD.htmlText = st;
The <p> tags still behave as a <br/> tag, but you can add an extra <br/> to simulate a paragraph.
Here is the example again with the updates,
HTML Code:
package
{
import flash.text.Font;
import flash.text.TextField;
import flash.text.AntiAliasType;
import flash.display.MovieClip;
import flash.text.StyleSheet;
public class test extends MovieClip
{
public function test()
{
//get font
var arial:Font = new _Arial();
//get textfield from stage
var _IDE_TextField:TextField = TextField(getChildByName("ideTextField"));
//text string
var _text:String;
//setup stylesheet
var _styles:StyleSheet = new StyleSheet();
var p_StyleObj:Object = new Object();
p_StyleObj.fontSize = "12";
p_StyleObj.color = "#000000";
p_StyleObj.fontFamily = arial.fontName;
_styles.setStyle("p", p_StyleObj);
var alink_StyleObj:Object = new Object();
alink_StyleObj.color = "#7CCCBF";
alink_StyleObj.fontWeight = "bold";
alink_StyleObj.textDecoration = "underline";
//
_styles.setStyle("a:link", alink_StyleObj);
var ahover_StyleObj:Object = new Object();
ahover_StyleObj.color = "#7CCCBF";
ahover_StyleObj.fontWeight = "bold";
ahover_StyleObj.textDecoration = "none";
//
_styles.setStyle("a:hover", ahover_StyleObj);
var aactive_StyleObj:Object = new Object();
aactive_StyleObj.color = "#7CCCBF";
aactive_StyleObj.fontWeight = "bold";
aactive_StyleObj.textDecoration = "none";
//
_styles.setStyle("a:active", aactive_StyleObj);
//dynamic textfield
var tf:TextField = new TextField();
tf.styleSheet = _styles;
tf.width = 500;
tf.height = 200;
tf.border = true;
tf.embedFonts = true;
tf.antiAliasType = AntiAliasType.ADVANCED;
tf.selectable = true;
tf.multiline = true;
tf.wordWrap = true;
tf.condenseWhite = false;
//ide textfield
_IDE_TextField.styleSheet = _styles;
_IDE_TextField.width = 500;
_IDE_TextField.height = 200;
_IDE_TextField.border = true;
_IDE_TextField.embedFonts = true;
_IDE_TextField.antiAliasType = AntiAliasType.ADVANCED;
_IDE_TextField.selectable = true;
_IDE_TextField.multiline = true;
_IDE_TextField.wordWrap = true;
_IDE_TextField.condenseWhite = false;
//
XML.ignoreWhitespace = false; //required as remove spaces between html tags
XML.prettyPrinting = false;
var textXml_doesnt_work:XML =
<text>
<p>first paragraph <a href="www.google.com">text</a> here</p>
<p>second paragraph text here</p>
<p>third paragraph text here</p>
</text>;
var textXml_othertags_ignored:XML =
<text>
<p>first paragraph <a href="www.google.com">text</a> here</p>
<br/><br/><br/><b></b><font></font><br></br>
<p>second paragraph text here</p>
<p>third paragraph text here</p>
</text>;
var textXml_works_forAS_textfield:XML =
<text>
<p>first paragraph <a href="www.google.com">text</a> here</p><p/><p>second paragraph text here</p><p>third paragraph text here</p>
</text>;
var textXml_works_forIDE_Textfield:XML =
<text><p>first paragraph <a href="www.google.com">text</a> here</p><p>second paragraph text here</p><p>third paragraph text here</p></text>;
var textXml_works_but_with_extra_paragrahs:XML =
<text>
<p>first paragraph <a href="www.google.com">text</a> here</p>
<p/>
<p>second paragraph text here</p>
<p>third paragraph text here</p>
</text>;
//grab the html from inside the <text> tags
_text = textXml_doesnt_work.children().toString();
//_text = textXml_othertags_ignored.children().toString();
//_text = textXml_works_forAS_textfield.children().toString();
//_text = textXml_works_forIDE_Textfield.children().toString();
//_text = textXml_works_but_with_extra_paragrahs.children().toString();
var st:String = encodeURI(_text);
var pattern:RegExp = /(%09)+|(%0A)+|(%0D)+/g;
st = st.replace(pattern, "");
//trace(st)
st = decodeURI(st);
_IDE_TextField.htmlText = st;
tf.htmlText = st;
addChild(tf);
}
}
}
Hope this helps someone