Skip to main content
Participating Frequently
September 5, 2010
Question

TextLayoutImporter and creating elements from XML

  • September 5, 2010
  • 1 reply
  • 569 views

I'm trying to use the functions available through the TextLayoutImporter class to create elements from XML. 

For example, I would like to use this xml:

var chase_xml:XML = new XML('<p>chase</p>');

in conjunction with the "createParagraphFromXML" method of the TextLayoutImporter class to create a ParagraphElement that I can add to an existing TextFlow using the "addChild" method of the TextFlow class.

Unfortunately, I keep getting an empty paragraph rather than the paragraph I am sending into the importer.

The code I've been tinkering with:

var _headerTextFlow = new TextFlow();

//using the same config as the TextFlow I already created, since that is what I understand the purpose of the config to be?  I also, unsuccessfully, tried setting it to null

var new_importer = new TextLayoutImporter(_headerTextFlow.configuration);

var spellParagraph:ParagraphElement = new_importer.createParagraphFromXML(spellXML);

trace('get text: '+spellParagraph.getText()); //this traces as 'get text:  '

_headerTextFlow.addChild(spellParagraph);

Is this function just non-functional?  It would be pretty useful to be able to go directly from XML marked up for the TextLayout Framework to FlowElements.  I was going to try to write a class to do just that when I dug into the source and found functions such as "createParagraphFromXML."  Unfortunately, they do not see to be working in a way I can understand...

This topic has been closed for replies.

1 reply

Adobe Employee
September 8, 2010

That class isn't tested for your use case.   It's actually not a public class - its marked with ExcludeClass and not part of the docs.  To hazard a guess I'd say its either a namespace mismatch issue or some sort of initialization issue.

Richard

Participating Frequently
September 9, 2010

Thank you for replying.

It's a shame that it's not tested for use, as it would be extremely useful.  I find that a lot of what I would find useful is lacking in the TLF (mainly with respect to XML -> FlowElements), so I had been hoping that by doing some digging I could find more.

Converting everything directly to a flow isn't quite right for my current project, which requires many containers containing one flow and sized to fit the text as it is formatted and added to the text flow.  The creation of each span, appending them to paragraphs, etc. gets very cumbersome code wise quite quickly.

I suppose I'll just have to write some parsers myself

Adobe Employee
September 10, 2010

Agreed that would be useful.  I don't think we'll get to it in the 2.0 cycle though.

If you do determine the problem here I'd be more than happy to integrate changes into the code so that 2.0 is more usable for you.

Richard