Skip to main content
Inspiring
Sep 10, 2010 4:18 PM UTC
Question

Weird issue round tripping with TLF

Hello,

I have an application that allows the user to drag and drop text elements into a design and modify their content (text, font, color, etc..)

They then save this which takes the textflow information and saves it to the server using XML, then when I want to bring up a saved design, it reads that xml from the server and renders it out on the design.

All works great except when I have a text item that uses multiple formats, for example

here is some text

where text is bold, but the rest is not.  If I have any spaces in my text before or after the format change, they disapear on the round trip to the server.

Is there an easy way to replace the spaces with non breaking space entities or something similar before sending it off to the server?

Thanks

This topic is closed to new replies. Start a new post to keep the conversation going.

4 replies

Inspiring
Sep 10, 2010 5:31 PM UTC

For the issue with spaces being removed from XML, its probably with the fact that XML's ignoreWhiteSpace property defaults to true.  Change it to false to preserve spaces.

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/XML .html#ignoreWhitespace

Translate
Sep 10, 2010 5:48 PM UTC

myIP is correct. At some point your code is converting a string into XML, and that's when the spaces are stripped out. You need to change the default whitespace handling before that happens.

XML.ignoreWhitespace = false;

var serverXML:XML = XML(res);

Translate
box86rowhAuthor
Inspiring
Sep 10, 2010 6:06 PM UTC

The problem is, my xml goes through a few processes before it hits the text object and if I turn off the ignorewhitespace at the beginning, the rest of my xml handling code breaks because of all the added whitespace in other places.

Translate
box86rowhAuthor
Inspiring
Sep 10, 2010 5:15 PM UTC

What I ended up doing, is on the point of save I make a copy of my textflow,

then loop through all spans and replace spaces with a carot ^, then on render, i loop through all spans and replace the ^ with the space.

This works perfect, although it is a hack.

ON SAVE :

                var copy:TextFlow = TextConverter.importToFlow(TextConverter.export(txt.textFlow,TextConverter.TEXT_LAYOUT_FORMAT, ConversionType.STRING_TYPE), TextConverter.TEXT_LAYOUT_FORMAT);
                for(var i:Number = 0; i < copy.numChildren; i++){
                    var p:ParagraphElement = copy.getChildAt(i) as ParagraphElement;
                    for(var j:Number = 0; j < p.numChildren; j++){
                        var s:SpanElement = p.getChildAt(j) as SpanElement;
                        s.text = s.text.split(" ").join("^");
                    }
                }
                var res:String = TextConverter.export(copy, TextConverter.TEXT_LAYOUT_FORMAT, ConversionType.STRING_TYPE).toString();

ON RENDER :

                for(var i:Number = 0; i < txt.textFlow.numChildren; i++){
                    var p:ParagraphElement = txt.textFlow.getChildAt(i) as ParagraphElement;
                    for(var j:Number = 0; j < p.numChildren; j++){
                        var s:SpanElement = p.getChildAt(j) as SpanElement;
                        s.text = s.text.split("^").join(" ");
                    }
                }

Translate