Skip to main content
Known Participant
June 4, 2010
Question

importToFlow(xml, ...) issue

  • June 4, 2010
  • 3 replies
  • 1830 views

package {
    import flash.display.Sprite;   
    import flashx.textLayout.container.ContainerController;
    import flashx.textLayout.elements.TextFlow;
    import flashx.textLayout.conversion.TextConverter;

    public class Test extends Sprite
    {
        public function Test()
        {   
            init();
        }
       
        private function init():void{       
           
            var markup1:XML = <TextFlow xmlns='http://ns.adobe.com/textLayout/2008'>
                                  <p fontSize="30" color="666666">
                                    <span>What a</span><br/>
                                    <span color='#5da325'>wonderful</span>
                                    <span>text (1)!</span>
                                </p>
                              </TextFlow>;
           
            creatTextFlow(markup1);
                       
            var markup2:XML =     <p fontSize="30" color="666666">
                                    <span>What a</span><br/>
                                    <span color='#5da325'>wonderful</span>
                                    <span>text (2)!</span>
                                </p>;
           
            text = markup2;
           
        }
       
        private function set text(tempXML:XML):void{
           
            var finalXML:XML =     <TextFlow xmlns='http://ns.adobe.com/textLayout/2008'/>;       
           
            finalXML.appendChild(tempXML);
                           
                           
            creatTextFlow(finalXML, 150);
        }
       
        private function creatTextFlow(xml:XML, cY:Number = 0):void{
           
            trace(xml);
           
//            trace xml of markup1:
//            <TextFlow xmlns="http://ns.adobe.com/textLayout/2008">
//                <p fontSize="30" color="666666">
//                    <span>What a</span>
//                    <br/>
//                    <span color="#5da325">wonderful</span>
//                    <span>text (1)!</span>
//                </p>
//            </TextFlow>
           
//            trace xml of markup2:
//            <TextFlow xmlns="http://ns.adobe.com/textLayout/2008">
//                <p fontSize="30" color="666666">
//                    <span>What a</span>
//                    <br/>
//                    <span color="#5da325">wonderful</span>
//                    <span>text (2)!</span>
//                </p>
//            </TextFlow>
           
//             MARKUP1 EQUALS MARKUP2 !!!!!!!!!!!
           
                       
            var textFlow:TextFlow = new TextFlow();                   
           
            // option 1:
            // import xml object, works only for markup1, not markup2!
            // markup 2 is not visible -----------> WHY !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ??? thats my question.
            // and the whitespace between the spans in markup1 is not visible
            textFlow = TextConverter.importToFlow(xml, TextConverter.TEXT_LAYOUT_FORMAT);
           
            // option 2:
            // import xml object as XMLString, works for both, BUT you get an UNREMOVABLE indent of the first 2 textlines.
            //textFlow = TextConverter.importToFlow(xml.toXMLString(), TextConverter.TEXT_LAYOUT_FORMAT);

            var sprite:Sprite = new Sprite();
           
            var controller:ContainerController = new ContainerController(sprite, 200, 200);
           
           
            textFlow.flowComposer.addController(controller);
           
            textFlow.flowComposer.updateAllControllers();
           
           
            addChild(sprite);
           
            sprite.y = cY;

        }
    }
}

This topic has been closed for replies.

3 replies

Known Participant
June 9, 2010

I fixed the problem with your help!

1st:  It makes absolutely sense to instance an ITextImporter and set the throwOnError property to true. thx for that.

2nd: set these values:

          private const ns:Namespace = new Namespace("xmlns", 'http://ns.adobe.com/textLayout/2008');

           XML.ignoreWhitespace = false;   
           XML.ignoreProcessingInstructions = true;
           XML.prettyPrinting = false;

3rd:

           finalXML = <TextFlow/>;

           finalXML.appendChild( tempXML.children());

           ...

Known Participant
June 7, 2010

The key question is, why get the finalXML not be displayed. I dont get an error.

            var markup:XML =   <p fontSize="30" color="666666">
                                              <span>What a</span><br/>
                                               <span color='#5da325'>wonderful</span>
                                              <span>text (2)!</span>
                                          </p>;                 

            var finalXML:XML =     <TextFlow xmlns='http://ns.adobe.com/textLayout/2008'/>;
                       
            finalXML.appendChild(markup);

// trace final XML:

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

<p fontSize="30" color="666666">

<span>What a</span>

<br/>

<span color="#5da325">wonderful</span>

<span>text (2)!</span>

</p>

</TextFlow>



textFlow = TextConverter.importToFlow(finalXML, TextConverter.TEXT_LAYOUT_FORMAT);

...

Adobe Employee
June 7, 2010

After the "importToFlow" function call you need to add a call to updateAllControllers() to display the result. As in:

textFlow.flowComposer.updateAllControllers();

Your code snippet doesn't show that; if it's missing, that would explain the missing text.

- robin

Known Participant
June 8, 2010

thanks again...., but

as I described in my first post, I know how to import the XML to TextFlow. of course I updatedAllControllers ... take a look at my first post, there, you will see the fullcode!

2 equal XML files, one works, one not. Thats the point and makes no sense at all!

Adobe Employee
June 7, 2010

I am not seeing exactly the same thing you're seeing. When I import either example, as a String, both work fine, except that the color attribute is reported as an error.

<?xml version="1.0" encoding="utf-8"?>

<TextFlow whiteSpaceCollapse="preserve" xmlns="http://ns.adobe.com/textLayout/2008"><p fontSize="30"><span> What a <br/> </span><span color="#5da325">wonderful</span><span> text (2)! </span></p></TextFlow>

If you pass it as an XML object, that should also work. Note that when you do a conversion from String to XML you will want to have ignoreWhitespace set correctly. My code makes this call before doing the conversion:

try

{

XML.ignoreProcessingInstructions = false;

XML.ignoreWhitespace = false;

xmlData = new XML(sourceString);

}

finally

{

XML.setSettings(originalSettings);

}

Hope this helps,
- robin

Known Participant
June 7, 2010

Thanks for your answer Robin!

I tried to import the markup as a String. The problem in that case is, that I get an Indent of the first two line, but the formatting is right!

It Looks like this:

  What a

  wonderful text

(2)!

var markupString:String = "<?xml version='1.0' encoding='utf-8'?><TextFlow whiteSpaceCollapse='preserve' xmlns='http://ns.adobe.com/textLayout/2008'><p fontSize='30'><span> What a <br/> </span><span color='#5da325'>wonderful</span><span> text (2)! </span></p></TextFlow>";

textFlow = TextConverter.importToFlow(markupString, TextConverter.TEXT_LAYOUT_FORMAT);

If you try that code, you get the same result?

The only way it works is to directly import the markup from xml with <Textflow ...> etc.

As I already described, when I read out my XML objects and merge them later into a TextFlow Object it does not show anything, BUT the XMLlooks exactly the same as that from the direct XML import with <TextFlow> included. Compare the traces at my first post (markup 1, markup2). Makes no sense at all!

I`m using TextLayoutFrameWork 1.0 from the Flex SDK 4.

Thanks!