Skip to main content
Participant
Sep 14, 2010 5:18 PM UTC
Answered

Adding formated Span at current position

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 is closed to new replies. Start a new post to keep the conversation going.
rdermerCorrect answer
Inspiring
Sep 15, 2010 5:02 AM UTC

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

3 replies

rdermerCorrect answer
Inspiring
Sep 15, 2010 5:02 AM UTC

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

Translate
Participant
Sep 16, 2010 9:06 AM UTC

Hi Richard.

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

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

Translate
Adobe Employee
Sep 16, 2010 4:27 PM UTC

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

Translate