Skip to main content
March 10, 2010
Question

How to use the ApplyElementStyleNameOperation?

  • March 10, 2010
  • 1 reply
  • 891 views

Hi,

I'm trying to appl style on a selected text using the "ApplyElementStyleNameOperation".

But what I get is that all the text from beginning of selection till end of text is deleted.

The code is as follows:

var txtSel:SelectionState= new SelectionState(_focusedTextArea.textFlow,_focusedTextArea.selectionAnchorPosition,_focusedTextArea.selectionActivePosition);

var applyStyle:ApplyElementStyleNameOperation = new ApplyElementStyleNameOperation(txtSel,_focusedTextArea.textFlow,STYLE_NAME,

_focusedTextArea

.selectionAnchorPosition,_focusedTextArea.selectionActivePosition);

var ed:EditManager = EditManager(_focusedTextArea.textFlow.interactionManager);

ed.doOperation(applyStyle);

I've debugged and found out that the flowElements disappears inside the EditManger.doOperation, after the line "operation = doInternal(operation);"

Can anyone help ?

This topic has been closed for replies.

1 reply

Adobe Employee
March 10, 2010

Not seeing that in my tests.

The ordering is a bit confusing here.  Does focusedTextArea.textFlow already have an EditManager attached to it?  I'd suggest just using that one if that's the case.

If that's not the case then you need to attach the EditManager to the TextFlow by assigning the EditManager as the textFlow. interactionManager property.

Hope that helps,

Richard

March 11, 2010

Yes, there is already an EditManager for the textFlow, and this is the one i'm using.

I've also tried calling ApplyElementStyleNameOperation.doOperation but it didn't work either.

I've continued debugging and found out that when the function getTargetElement in

FlowElementOperation is called, it performs

splitAtPosition which acts also on my original textFlow, and this is why it's being cut.

Maybe there is a problem with the arguments I'm sending to the ApplyElementStyleNameOperation constructor ?

Should I send a copy of the textFlow?

(I'm using tlf that comes with flashBuilder4Beta.)

I'd also appreciate it if you can send me a sample code where it works.

Thanks,

Dafna.

Adobe Employee
March 11, 2010

I think I see what's going on.  You are passing the textFlow as the object that should have its style name changed.  Its being split into pieces.  If that's your goal than modify your StyleNameOperation to supply 0 and textFlow.textLength.

FWIW the way all that code you've written is exactly the same as this one line:

EditManager(_focusedTextArea.textFlow).changeStyleName(_focusedTextArea.textFlow,STYLE_NAME).

Check out the changeStyleName docs.

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flashx/textLayout/edit/IEditManager.html#changeStyleName%28%29

In my one line just as inyour code a TextFlow is passed and the operation is asked to apply the styleName to part of it.  The TextFlow is getting chopped into bits and parts are being discarded.

That's probably not your goal here - I think you want to style the spans?  Or the paragraphs?  Hard to say.

Hope that helps,

Richard