PDA

View Full Version : HTML Text Not Displaying


dcster2001
11-09-2007, 04:01 PM
I've created a textfield in a TextBox class that will display textfield.text properly, but I am having trouble displaying textfield.htmlText. Here's what I've got:

private var txtfld:TextField;

// Create the TextField
private function createTextField ():void {
txtfld = new TextField();
txtfld.width = 378;
txtfld.height = 244;
txtfld.embedFonts = true;
txtfld.antiAliasType = AntiAliasType.ADVANCED;
txtfld.gridFitType = GridFitType.PIXEL;
txtfld.selectable = false;
txtfld.wordWrap = true
txtfld.htmlText = "<p align='center'><b>TEXT TEST</b>";
// Apply formatting
txtfld.setTextFormat(format);
// Add textfield to display list
addChild(txtfld);
}

"TEXT TEST" displays as it should.

However, when I try to add html-formatted text outside of the txtfld creation function via setHtmlText("SomeHTMLString") (or even explicitly in the TextBox() constructor body via txtfld.htmlText = "SomeHTMLString" after the textfield is created) it doesn't display. Here's the setHtmlText() code:

// Assign htmlText to txtfld
public function setHtmlText (txt:String):void {
txtfld.htmlText = txt;
}

Is there some other sort of formatting that I need to apply to get it to work? I even included a <FONT FACE="Arial"> tag to ensure the embedded font was accessible, but it still doesn't display any htmlText outside of the txtfld creation function.

A setText method does work, however:
// Assign text to txtfld
public function setText (txt:String):void {
txtfld.text = txt;
// Apply formatting
txtfld.setTextFormat(format);
}

Any help is appreciated.

dcster2001
11-11-2007, 01:06 AM
OKay, here's the solution:

#1 If the htmlText has any <P> or <BR> tags, textField.multiline property must be set to 'true' (default is 'false').

#2 It appears that each <P> block must include its own font format when using embedded fonts, such as <FONT FACE="Arial" SIZE="12" COLOR="#00CC33">. This also includes any <B> or <I> tags.

The htmlText in #2 above will display, but <FONT> formatting will not carry over from paragraph to paragraph, even though the <FONT> tag is not terminated by a </FONT> end tag. For consistency therefore, I terminated each paragragh with a </FONT> end tag. Now, it all displays correctly.

Cheers.