Skip to main content
Participant
June 15, 2010
Question

1.5 days trying to read TextFlow back from database

  • June 15, 2010
  • 1 reply
  • 711 views

I'm experimenting with a TextArea that has a textFlow

<s:TextArea id="mytextarea">
        <s:textFlow>
                <s:TextFlow id="mytextflow">
                </s:TextFlow>
        </s:textFlow>
</s:TextArea>

I'm trying to load into it TextFlow data that's stored in a database. It looks like this in the database, but I've removed many of the properties to make it more readable here.

<TextFlow xmlns="http://ns.adobe.com/textLayout/2008">

        <p direction="ltr" >

                 <span>some text</span>

                 <span >some additional text</span>

                 <span> and some additional text</span>

        </p>

        <p direction="ltr" >

                 <span>some text</span>

                 <span>some additional text</span>

                 <span> more text</span>

        </p>

</TextFlow>

I get this TextFlow as one of several data from the database, all in XML format, so the output Flex receives looks like this.

<?xml version="1.0" encoding="utf-8"?>
<data1>this is data 1</data1>

<data2>this is data 2</data2>

<data3>

      <3a>this is data 3a</3a>

      <3b>this is data 3b</3b>

      <3c>

            <TextFlow xmlns="http://ns.adobe.com/textLayout/2008">

                    <p direction="ltr" >

                           <span>some text</span>

                           <span>some additional text</span>

                           <span> and some additional text</span>

                    </p>

                    <p direction="ltr">

                           <span>some text</span>

                           <span>some additional text</span>

                           <span> more text</span>

                    </p>

             </TextFlow>

       </3c>

</data3>

When the data returns, I can read all the other data correctly, except data3->3c which contains the TextFlow. I've tried these among many other things, but nothing works.

mytextarea.textFlow  =

TextConverter.importToFlow(event.result.data3.3c, TextConverter.TEXT_LAYOUT_FORMAT);

mytextarea.textFlow  =

TextFlowUtil.importFromXML(event.result.data3.3c, "preserve");

mytextarea.textFlow  =

TextFlowUtil.importFromXML(event.result.data3.3c.TextFlow[0], "preserve");

It's frustrating, I'm new to TLF, but I can't see what's wrong with this approach. Any help appreciated.

This topic has been closed for replies.

1 reply

Adobe Employee
June 15, 2010

Looks to me as if you are passing the entire <3C> XML object to the TextConverter. The TextConverter needs to get the <TextFlow> object itself, so try going down a level, and passing just the TextFlow.

- robin

duder2Author
Participant
June 15, 2010

Doesn't seem to be it. When I try this, it still doesn't work.

mytextarea.textFlow = TextConverter.importToFlow(event.result.data3.3c.TextFlow, TextConverter.TEXT_LAYOUT_FORMAT);

Is anyone getting the same error with this case?

Adobe Employee
June 17, 2010

I tried this example and had to change around a few things in the XML. What you posted (or at least what I copied off) is not valid XML. I added a single root element that includes the three data1, data2, etc. elements, and changed the element names that start with digits to start with letters (XML element names may not start with numbers). Once I did this, the TextConverter seems to find the TextFlow on its own.

Here's my example:

        private var markup:XML =
            <root>
                <data1>this is data 1</data1>               
                <data2>this is data 2</data2>               
                <data3>               
                      <a>this is data 3a</a>               
                      <b>this is data 3b</b>               
                      <c>               
                            <TextFlow xmlns="http://ns.adobe.com/textLayout/2008">               
                                    <p direction="ltr" >               
                                           <span>some text</span>               
                                           <span>some additional text</span>               
                                           <span> and some additional text</span>               
                                    </p>               
                                    <p direction="ltr">               
                                           <span>some text</span>               
                                           <span>some additional text</span>               
                                           <span> more text</span>               
                                    </p>               
                             </TextFlow>               
                       </c>   
                </data3>
            </root>;
       
        public function Test()
        {
            var s:Sprite = new Sprite();
            s.x = 100;
            s.y = 100;
            addChild(s);

            var textFlow:TextFlow = TextConverter.importToFlow(markup, TextConverter.TEXT_LAYOUT_FORMAT);
            var controller:ContainerController = new ContainerController(s, 500, 500);
            textFlow.flowComposer.addController(controller);
            textFlow.flowComposer.updateAllControllers();
        }

- robin