Skip to main content
Jun 23, 2009 6:12 PM UTC
Question

Adding Text/Link/InlineGraphic to middle of TextFlow

I have a text flow object that I want to add more FlowElements to. I want the FlowElements to be added to the last place the user clicked in the text flow.

What I've tried is below.

I create an xml object and add a link, image and some spans to a paragraph and then try to add it to the text flow that is already displaied.

private function addNewText()

{

     var xml:XML = new XML(
     <p>
          <a href="www.byu.edu" target="_self" >
               <img height="auto" width="auto" source="http://www.insideria.com/riaimages/rss_icon.

          </a>
          <span>There are many </span>
          <span fontStyle="italic">such </span>
          <span>lime-kilns in that tract of country, for the purpose of burning the white</span></p>
     );

     var text:TextFlow = textArea.textFlow;//Get the current text flow from the text area.
     var newtext:TextFlow = TextFlowUtil.importFromXML(xml); //create a new text flow with the xml.
     var split:FlowElement = text.splitAtPosition(addAt);//split the current text flow at the last place the mouse/(blinky add text here icon) was.
     var t:TextFlow = new TextFlow();//create an empty flow
     t.addChild(split);//I think this should add the first part.
     t.addChild(newtext.getChildAtIndex(0));//I think this should add the new stuff
     t.addChild(text);//I think this should the old end stuff.

     textArea.textFlow = t;//display it.

I know I'm not doing something right. I've only been using TLF for 2 days now so any help would be great.

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

5 replies

Known Participant
Sep 10, 2009 12:23 AM UTC

Hey,

Have you figured out a good solution to this?  I'm facing the same challenge and wanted to know if you could share your experience.

Thanks man,

Lance

Translate
Adobe Employee
Sep 10, 2009 4:12 PM UTC

The easiest way to add a link or inline graphic is to use the methods in EditManager. So, given you have a TextFlow, and you want to add a new link at the current selection, you might code it something like this:

          textFlow.interactionManager = new EditManager();

            (textFlow.interationManager as IEditManager).applyLink("http://www.cnn.com");

Likewise, for an inline grapic, you could do this:

            (textFlow.interationManager as IEditManager).insertInlineGraphic("myImg.png", Number(10), Number(10));

Hope this helps!

- robin

Translate
Adobe Employee
Jun 28, 2009 8:18 PM UTC

One problem may be that your XML snippet isn't a fully qualified TextFlow. Try wrapping it with a TextFlow element:

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

     ... your content here ...

</TextFlow>

I suspect the call to importFromXML is not returning the TextFlow you expect.

Translate