Skip to main content
Participant
August 26, 2010
Question

add flowElement inside existing Text Flow

  • August 26, 2010
  • 1 reply
  • 760 views

Hi,

I have a problem with adding textFlow element inside textFlow in a position which i want which is editor.selectionAnchorPosition

I used simply addchild method but it add my new flow element at the end of the textflow, and addChildAt is not working as it suppose to work 😕😕

var p:ParagraphElement = new ParagraphElement();

var img:InlineGraphicElement = new InlineGraphicElement();

img.source = "assets/images/Image1.png";

img.height = 9;

img.width = 9;

p.addChild(img);

editor.textFlow.addChild(p);

is there any solution to insert flowElement in a place where selectionAnchorPosition is ?

Message was edited by: Othil

This topic has been closed for replies.

1 reply

August 26, 2010

If you have an EditManager, using the methods on that object will be your best bet (EditManager.insertInlineGraphic, in this case).

addChildAt() works with element indices, not character position. So if you have a TextFlow with two paragraphs, calling addChildAt with index 1 will add the child in between the paragraphs (no matter how many characters the paragraphs contain). Here's an example that places a new paragraph in-between the two existing paragraph children:

var tf:TextFlow = new TextFlow(); var p1:ParagraphElement = new ParagraphElement(); var span1:SpanElement = new SpanElement(); span1.text = "one"; p1.addChild(span1); var p2:ParagraphElement = new ParagraphElement(); var span2:SpanElement = new SpanElement(); span2.text = "two"; p2.addChild(span2); tf.addChild(p1); tf.addChild(p2); var insertPara:ParagraphElement = new ParagraphElement(); var insertSpan:SpanElement = new SpanElement(); insertSpan.text = "inserted"; insertPara.addChild(insertSpan); tf.addChildAt(1,insertPara);

What you get as a result looks like this:

one

inserted

two

OthilAuthor
Participant
August 26, 2010

Thank you for help, I used EditManager and it finaly work

var editManager:EditManager = new EditManager();

var position:int = editor.selectionAnchorPosition;

editor.textFlow.interactionManager = editManager;

editManager.selectRange(position,position);

editManager.insertInlineGraphic("assets/images/Image1.png",9,9);