Skip to main content
Known Participant
Jan 25, 2011 6:25 PM UTC
Answered

editManager.splitParagraph(); inherits previous paragraph format

So here is a function that I'm using in a screenwriting application that is suppose to drop down a line, center it and cause the next line to be all caps.  However, the new paragraph inherits the previous paragraph's format.  Am I doing this right?  Is there a better way?  How can I cause a new paragraph to be inserted here with the new format?

public function character():void {

var cf:TextLayoutFormat = new TextLayoutFormat();

editManager.splitParagraph();

cf.paragraphSpaceBefore="10";

cf.textAlign = "center";

cf.typographicCase="uppercase";

IEditManager(textFlow.interactionManager).applyParagraphFormat(cf);

textFlow.interactionManager.setFocus();

}

thanks,

This topic is closed to new replies. Start a new post to keep the conversation going.
rdermerCorrect answer
Inspiring
Jan 25, 2011 9:56 PM UTC

What you have here doesn't quite work because it only adds new formats.  In this case you want to use the clearFormatOperation to clear the ones that were copied first.  Before applyParagraphFormat call:

IEditManager(textFlow.interactionManager).clearFormat(null,TextLayoutFormat.defaultFormat,null);

In TLF 2.0 splitParagraph returns the newly created ParagraphElement.  You can then use clearFormatOnElement followed by applyFormatToElement to adjust clear any cloned styles from the previous paragraph and apply your desired styles.

In both cases wrap the splitParagraph, and the clear and apply formats up in a call to beginCompositeOperation/endCompositeOperation and it will be packaged up in a single undoable operation.

The setFocus call shouldn't be necessary.

Hope that helps,

Richard

16 replies

ddfletchAuthor
Known Participant
Jan 25, 2011 9:57 PM UTC

I've got most of the inherit issues solved but the typographicCase="uppercase"; for some reason will always stay uppercase, even when I've split the paragraph and changed the case to typographicCase="default";

Translate
rdermerCorrect answer
Inspiring
Jan 25, 2011 9:56 PM UTC

What you have here doesn't quite work because it only adds new formats.  In this case you want to use the clearFormatOperation to clear the ones that were copied first.  Before applyParagraphFormat call:

IEditManager(textFlow.interactionManager).clearFormat(null,TextLayoutFormat.defaultFormat,null);

In TLF 2.0 splitParagraph returns the newly created ParagraphElement.  You can then use clearFormatOnElement followed by applyFormatToElement to adjust clear any cloned styles from the previous paragraph and apply your desired styles.

In both cases wrap the splitParagraph, and the clear and apply formats up in a call to beginCompositeOperation/endCompositeOperation and it will be packaged up in a single undoable operation.

The setFocus call shouldn't be necessary.

Hope that helps,

Richard

Translate
ddfletchAuthor
Known Participant
Jan 25, 2011 11:04 PM UTC

I can't figure out why but your line of code

IEditManager(textFlow.interactionManager).clearFormat(null,TextLayoutFormat.defaultFormat,null);

is throwing an error.

1061: Call to a possibly undefined method clearFormat through a reference with static type flashx.textLayout.edit:IEditManager.

Translate
Inspiring
Jan 25, 2011 11:13 PM UTC

I don't either - that's been around since TLF 1.0.

Try this:

var em: IEditManager = textFlow.interactionManager as IEditManager;

if (!em)

     trace("not an edit manager");

em.clearFormat(null,TextLayoutF ormat.defaultFormat,null);

Does it compile?

Richard

Translate