PDA

View Full Version : HTML text not rendering properly in AS created text field



Yuu
August 28th, 2008, 10:46 AM
Well the title says it all.
I've got a text field placed (w/ a font from the library) on the stage via AS and populated with HTML text. For some reason, none of the HTML elements that would cause a line break will render, it's like they are not there.

If I send the same text to a field drawn on the stage, it all renders properly.

I have a feeling I'm just missing some little setting for the field, but searching around hasn't gotten me anywhere.

- AS (from the timeline for simplicy). Here's a link to the files so you have the XML file and font if you feel like messing around with it. http://www.batescreativegroup.com/test/AS3Text.zip

Thanks
ActionScript Code:

stop();
import flash.net.URLRequest;
import flash.events.Event;

//////////////////////////////////
var body:TextField = new TextField();

//Position the text field
body.x = 50;
body.y = 50;
//Font from Library
var harmony:Font = new _Harmony();

// Formatting for the Body Field
var bodyText:TextFormat = new TextFormat();
bodyText.font = harmony.fontName;
bodyText.color = 0xFFFFFF;
bodyText.size = 8;
bodyText.leading = 3;

body.embedFonts = true;
body.defaultTextFormat = bodyText;
body.width = 190;
body.wordWrap = true;
body.autoSize = TextFieldAutoSize.LEFT;
body.multiline
body.border = false;
body.borderColor = 0x000000;
body.selectable = false;
body.antiAliasType = AntiAliasType.NORMAL;

this.addChild(body);

////////////////////////////////////////////////////


var newsXml:XML = new XML();
var newsXmlLoader:URLLoader = new URLLoader();
newsXmlLoader.load(new URLRequest("HTML_test.xml"));
newsXmlLoader.addEventListener(Event.COMPLETE, newsTextReady)

function newsTextReady(evt:Event):void {
newsXml = XML(evt.target.data);
var XmlNewsItemTotal:Number = (newsXml.entry.length());
var str:String = "";
var i:uint = new uint();
for (i = 0; i < XmlNewsItemTotal; i++)
{ // trace("XML News Item number " + i);
str += "<p>";
str += (newsXml.entry.@title.toXMLString());
str += "</p>";
str += (newsXml.entry[i].body);
};

[I]//Body is AS created text field
body.htmlText = str;
//drawnField is the text field drawn on the stage manually
drawnField.htmlText = str;

};

kipty
August 29th, 2008, 11:22 AM
i have the same problem, after reading your post, i tried the same with a textfield drawn on stage, like you say the results are different if you us a dynamically created TF,
see http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?catid=665&threadid=1386999

doing my head in!!!

Yuu
August 29th, 2008, 04:27 PM
Well after some time, I found the problem with my code. I managed to put in body.multiline - but left of = true...

Wow. gald I found that.. but feelign dumb that I did it in the 1st place\.