Archive for February, 2011
Ran into an issue today trying to figure out how to append additional html formatted text to a Spark TextArea component. As stated here the insertText() and appendText() methods always add the new text as a literal string, meaning the html content doesn't get parsed.
In Spark, when you're dealing with the text components and doing any sort of formatting, you're going to be dealing with TLF, the Text Layout Framework. It's a complete pain in the ass and makes me sad to see how horrific flash/flex development has become. Anyway, with TLF you're generally going to be dealing with TextFlow objects when getting/setting text on a text component. On top of that, you'll be importing and exporting the text by running things through helper classes such as TextFlowUtil and TextConverter.
Here's how I managed to "append" html text to a TextArea, in quotes because it actually exports the old text, merges the new text, and reassigns the whole things as the new content:
var oldText:String = TextConverter.export(messageOutput.textFlow, TextConverter.TEXT_FIELD_HTML_FORMAT, ConversionType.STRING_TYPE) as String;
messageOutput.textFlow = TextConverter.importToFlow(oldText + message, TextConverter.TEXT_FIELD_HTML_FORMAT);
Definitely not as cool as textArea.htmlText.