Skip to main content
Participant
September 14, 2010
Answered

Adding formated Span at current position

  • September 14, 2010
  • 1 reply
  • 640 views

Hi,

I want to have an external button that will insert a formatted SpanElement at current position.

How can I insert my own elements in the required(cursor) position?

Element might look like:

var span:SpanElement = new SpanElement();

span.text = text; span.setStyle('custom',true);

span.color = '0xFF0000';

Thank you

This topic has been closed for replies.
Correct answer rdermer

Find the leaf element using texFlow.findLeaf.  If the position to insert is in the middle of a span use splitAtPosition to split it in two.

Compute the index you want to add the new span at using parent.getChildIndex and now the replaceChildren API can insert your new span.

Hope that helps,

Richard

1 reply

rdermerCorrect answer
Adobe Employee
September 15, 2010

Find the leaf element using texFlow.findLeaf.  If the position to insert is in the middle of a span use splitAtPosition to split it in two.

Compute the index you want to add the new span at using parent.getChildIndex and now the replaceChildren API can insert your new span.

Hope that helps,

Richard

Participant
September 16, 2010

Hi Richard.

Your idea  helped alot, but now I have another problem.

I think TextFlow merges the spans somehow. Any idea on that ?

Adobe Employee
September 16, 2010

Adjacent spans with identical attributes are merged when TLF recomposes the text. If you have a span that should not be merged, assign it an id.

- robin