Question

I'm importing text in from an xml file and i'm using htmlText to try to keep some styling with tags. I have both the regular and bold face font embedded, and the bolding works fine. The problem is that it ads spaces around the words in bold like a paragraph indent and then makes a line-break after them. What's going on, is there a way to fix?

fromxmlText.htmlText = theXML.contenttext;

If I pull the text in from a txt file it will work fine, but taking it out of an xml file causing funky formatting. lil' help?

Was it helpful?

Solution

To add HTML into XML you must use CDATA blocks otherwise the HTML is considered part of the XML document.

e.g.

<root>
    <someHtml><![CDATA[I can contain<br />html tags]]></someHtml>
    <somePlainText>I cannot contain html tags since they will be 
                   seen as XML nodes</somePlainText>
</root>

Also make sure you are saving your XML files with unix line endings and encoded as utf-8. If you are using windows line endings (\r\n) then Flash tends to double space newlines. Your editor should allow you to specify the line endings.

OTHER TIPS

I was importing a dynamic rss feed into a flash ad of mine that had html tags embedded. I was having the same problem. I used regex to find and replace. Here is the function I was using. you can prob use my regex code in there to do the same thing. It seems like we were having the same problem. Hope this helps:

function Parserover_feature(rover_feature:XML):void {

var s:String = rover_feature.items.item[0].article;
s = s.replace(/(?:<br>)+/gi, '<br>');
s = s.replace(/\n/g, '');
container.info_txt.htmlText = s
//trace (s);

}

It's hard to say without seeing your XML, but try fiddling with the global XML properties especially ignoreWhitespace. Depending on your line endings, you may also need to strip them before putting the text into the textfield.

if you are embedding from xml then make sure that you are using CDATA tags to show preformatted code, otherwise you are outputting the content of multiple nodes in XML.

see w3 schools for more info.

Also make sure your textField is set to multiline before you set your textField.htmlText = xml with
i.e.

var myText:TextField = new TextField();
myText.multiline = true;
myText.htmlText = (your xml node with the <br/ >);
addChild(myText);

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top