问题
I'm looking to simply append the following text to an existing spark.components.TextArea
's text flow:
<b>something</b>: hello world
I have attempted to do this using the following code, but nothing happens:
this.textarea.textFlow.addChild(TextConverter.importToFlow(
"<b>something</b>: hello world",
TextConverter.TEXT_FIELD_HTML_FORMAT));
How can I accomplish this? I know in the old mx.controls.TextArea
component, I could simply do:
this.textarea.htmlText += "<b>something</b>: hello world";
How can I do this with the new TLF/FTE API expressed in the spark.components.TextArea
component?
回答1:
I understand your pain with this one. This is the workaround I came up with:
var tf:TextFlow = TextConverter.importToFlow("<b>something</b>: hello world", TextConverter.TEXT_FIELD_HTML_FORMAT);
var pe:ParagraphElement = tf.mxmlChildren[0];
for each (var fe:FlowElement in pe.mxmlChildren)
some_paragraph_element.addChild(fe);
Ultimately, you need to grab all the objects in the generated TextFlow. For simplicity, I'm not doing that here. But you see how I still iterate over all objects in the first and only paragraph in the generated TextFlow?
Hope this helps and good luck.
回答2:
Another and ugly way to do could be : - Export the existing TextFlow into an HTML String. - Append to the another HTML String - Re-Import the Result
var helloWorldStr : String = "<b>something</b>: hello world";
var export : Object = TextConverter.export(textFlow,TextConverter.TEXT_FIELD_HTML_FORMAT, ConversionType.STRING_TYPE);
textFlow = TextConverter.importToFlow((export as String) + helloWorldStr, TextConverter.TEXT_FIELD_HTML_FORMAT);
来源:https://stackoverflow.com/questions/6024012/append-a-flow-to-an-existing-textflow