Skip to main content
Inspiring
June 22, 2011
Answered

how convert an xml to string for a textflow

  • June 22, 2011
  • 1 reply
  • 1568 views

Hi

usually I use fields type String to feed the textFlows.

now for visual convenience, I would like to store them in file formatted XML, and the thing succeeds well, but when I want use them I have problems, because the formatting XML creates line spacings that I don't want,

for example:

<TextFlow columnCount="inherit" columnGap="inherit" columnWidth="inherit" lineBreak="toFit" paddingBottom="4" paddingLeft="4" paddingRight="4" paddingTop="4" paragraphSpaceAfter="15" paragraphSpaceBefore="0" verticalAlign="top" id="flow" whiteSpaceCollapse="preserve" xmlns="http://ns.adobe.com/textLayout/2008">

  <linkActiveFormat>

    <TextLayoutFormat color="#cc00cc" fontWeight="bold" textDecoration="underline"/>

  </linkActiveFormat>

  <linkHoverFormat>

    <TextLayoutFormat color="#cc0000" fontWeight="bold" textDecoration="underline"/>

  </linkHoverFormat>

  <linkNormalFormat>

    <TextLayoutFormat color="#000099" fontWeight="bold" textDecoration="none"/>

  </linkNormalFormat>

  <p color="#990099" fontSize="15">

    <span>Gestione dei testi con TLF e Testo classico</span>

  </p>

  <p color="#666555" fontFamily="Arial" fontSize="14">

    <span>Le novità introdotte con l'ultima release di Flash CS5 sono molteplici, una di queste novità riguarda i campi di testo.</span>

  </p>

  <p color="#990099" fontSize="15">

    <span>Cosa c'è da sapere sul Text Layout Framework (TLF)?</span>

    <img id="1|emot|0" height="18" width="18" source="[object Bitmap]"/>

    <span></span>

  </p>

  <p color="#666555" fontFamily="Arial" fontSize="14">

    <span>Che rispetto al Testo Classico,</span>

  </p>

</TextFlow>

produce me:

init--------------------------------------------------------------

    Gestione dei testi con TLF e Testo classico

    Le novità introdotte con l'ultima release di Flash CS5 sono molteplici, una di queste novità riguarda i campi di testo.

    Cosa c'è da sapere sul Text Layout Framework (TLF)?

   

    Che rispetto al Testo Classico,

--------------------------------------------------------------------- end

instead of:

init--------------------------------------------------------------

Gestione dei testi con TLF e Testo classico
Le novità introdotte con l'ultima release di Flash CS5 sono molteplici, una di queste novità riguarda i campi di testo.
Cosa c'è da sapere sul Text Layout Framework (TLF)?
Che rispetto al Testo Classico,

--------------------------------------------------------------------- end

as I will want.
Now i see that with spark.utils i can use importFromXML to convert in a textFlow with collapse the line in excess, but unfortunately the class spark is not visible in Flash/as3.
can you help me?
thanks in advance
jeanPaul
This topic has been closed for replies.
Correct answer Jin-Huang

        config = new Configuration();
        format = new TextLayoutFormat(config.textFlowInitialFormat);
        format.whiteSpaceCollapse = "collapse";
        config.textFlowInitialFormat = format;
        collapsingTextLayoutImporter = TextConverter.getImporter(
        TextConverter.TEXT_LAYOUT_FORMAT, config);


Flex SDK is opensource. The code scrap above is from spark.utils.TextFlowUtil.

1 reply

Jin-HuangCorrect answer
Adobe Employee
June 22, 2011

        config = new Configuration();
        format = new TextLayoutFormat(config.textFlowInitialFormat);
        format.whiteSpaceCollapse = "collapse";
        config.textFlowInitialFormat = format;
        collapsingTextLayoutImporter = TextConverter.getImporter(
        TextConverter.TEXT_LAYOUT_FORMAT, config);


Flex SDK is opensource. The code scrap above is from spark.utils.TextFlowUtil.

Inspiring
June 22, 2011

hi Jin-Huang

ok I tested ur code as this:

markup = e.target.data;

var config:Configuration = new Configuration();

var format:TextLayoutFormat = new TextLayoutFormat(config.textFlowInitialFormat);

format.whiteSpaceCollapse = "collapse";

config.textFlowInitialFormat = format;

var cTI:ITextImporter = TextConverter.getImporter(TextConverter.TEXT_LAYOUT_FORMAT, config);

var flow:TextFlow = new TextFlow;

flow = TextConverter.importToFlow(markup,TextConverter.TEXT_LAYOUT_FORMAT,cTI);

and everything well up to here, but when I want to export the textFlow this way:

markup = TextConverter.export(flow,

  TextConverter.TEXT_LAYOUT_FORMAT,ConversionType.STRING_TYPE) as String;

I receive this error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.

where am I wrong?

Inspiring
June 23, 2011

MEA CULPA

I tried to load a file with three textFlows, and naturally the code give an error.

nevertheless after having corrected the file input the lines in more remain.

I have decided, to not waste other time, to export the textFlows in the two formats (String and XML), using the file String when I have to reload, while I will use XML   for a best legibility.

bye


I apologize with all for the loss of time, I've created an elephant from a little mouse.

the code working correctly is very simple, it's enough to replace the first line of the code:

   var markup:String = e.target.data;

with

   var markup:XML = new XML(e.target.data);

and all work correctly; but also:

   var markup:XML = new XML(e.target.data);

   var flow:TextFlow = new TextFlow;

   flow = TextConverter.importToFlow(markup,TextConverter.TEXT_LAYOUT_FORMAT);

gets the wanted result, verifiable with:

   trace( TextConverter.export(flow, TextConverter.TEXT_LAYOUT_FORMAT,ConversionType.STRING_TYPE) as String);