Search code examples
flashactionscript-3texttlf

Append a flow to an existing TextFlow?


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?


Solution

  • 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.