Skip to main content
Known Participant
October 27, 2009
Answered

Problem with TextConverter.importToFlow

  • October 27, 2009
  • 1 reply
  • 1097 views

Hi !

I am getting better thanks to the first response of Richard on my first post. And now format and applying format is not anymore a problem for me !

But now I have a little problem with the TextConverter.importToFlow 

The aim : A user create his own text by editing/pasting, and changing style. Then he save it. So  I convert my textflow in a xml and save an XML file.

Then he open this file. So I have to convert the xml into a TextFlow type to display it in my AIR application.

My XML : (details)

  <note>
      <TextFlow columnCount="inherit" columnGap="inherit" columnWidth="inherit" lineBreak="inherit" paddingBottom="inherit" paddingLeft="inherit" paddingRight="inherit" paddingTop="inherit" verticalAlign="inherit" whiteSpaceCollapse="preserve" xmlns="http://ns.adobe.com/textLayout/2008">
        <p>

          <span>Tout animal (l'homme y compris) qui vient de manger depense dans les heures qui suivent une energie</span>
          <span textDecoration="underline">importante consacre</span>
          <span>a  sa digestion stomacale.</span>
        </p>
      </TextFlow>
   </note>

My problem is :

I don't know why but i can't do

myXML.TextFlow

or

myXML.child("TextFlow").

An error compil appears (null reference).

After few tests, I found that  xmlns="http://ns.adobe.com/textLayout/2008" TextFlow's argument is the source of the error compil.

But I have to give only the balise <TextFlow> to the method importToFlow without the <note>. What I am suppose to do? I cant access to the <TextFlow> balise...

public function updateDetails( details:XML ) : void
        {
            if (details != null)
            {
                var loadTextFlow:TextFlow = TextConverter.importToFlow(details.toString(), TextConverter.TEXT_LAYOUT_FORMAT);
                _textFlow = loadTextFlow;
                _textFlow.interactionManager = new EditManager(new UndoManager());
                _textFlow.interactionManager.selectRange(0,0);
                _textFlow.flowComposer.updateAllControllers();
                _textFlow.interactionManager.setFocus();
            }
        }

Thank you for your help

This topic has been closed for replies.
Correct answer rdermer

This works:

        static public const noteXML:XML = <note>
      <TextFlow columnCount="inherit" columnGap="inherit" columnWidth="inherit" lineBreak="inherit" paddingBottom="inherit" paddingLeft="inherit" paddingRight="inherit" paddingTop="inherit" verticalAlign="inherit" whiteSpaceCollapse="preserve" xmlns="http://ns.adobe.com/textLayout/2008">
        <p>

          <span>Tout animal (l'homme y compris) qui vient de manger depense dans les heures qui suivent une energie</span>
          <span textDecoration="underline">importante consacre</span>
          <span>a  sa digestion stomacale.</span>
        </p>
      </TextFlow>
   </note>
           
        private function importIt():TextFlow
        {
            var textFlowXML:XML = noteXML..*::TextFlow[0];
            var textFlow:TextFlow = TextConverter.importToFlow(textFlowXML, TextConverter.TEXT_LAYOUT_FORMAT);
            return textFlow;   
        }

Might want to read the E4X docs if you're planning on doing lots of XML manipulation. Here's a good starting place:

http://help.adobe.com/en_US/AS3LCR/Flash_10.0/XML.html

MIght add - this is a namespace issue - it seems like it should be simpler than what I wrote above but I haven't been able to simplify it.

Hope that helps,

Richard

1 reply

rdermerCorrect answer
Adobe Employee
October 27, 2009

This works:

        static public const noteXML:XML = <note>
      <TextFlow columnCount="inherit" columnGap="inherit" columnWidth="inherit" lineBreak="inherit" paddingBottom="inherit" paddingLeft="inherit" paddingRight="inherit" paddingTop="inherit" verticalAlign="inherit" whiteSpaceCollapse="preserve" xmlns="http://ns.adobe.com/textLayout/2008">
        <p>

          <span>Tout animal (l'homme y compris) qui vient de manger depense dans les heures qui suivent une energie</span>
          <span textDecoration="underline">importante consacre</span>
          <span>a  sa digestion stomacale.</span>
        </p>
      </TextFlow>
   </note>
           
        private function importIt():TextFlow
        {
            var textFlowXML:XML = noteXML..*::TextFlow[0];
            var textFlow:TextFlow = TextConverter.importToFlow(textFlowXML, TextConverter.TEXT_LAYOUT_FORMAT);
            return textFlow;   
        }

Might want to read the E4X docs if you're planning on doing lots of XML manipulation. Here's a good starting place:

http://help.adobe.com/en_US/AS3LCR/Flash_10.0/XML.html

MIght add - this is a namespace issue - it seems like it should be simpler than what I wrote above but I haven't been able to simplify it.

Hope that helps,

Richard

Known Participant
October 29, 2009

Thanks Richard.

I already work with E4X and XML in flex. But I never work with Component in it, and with namespace with E4X.