Skip to main content
Known Participant
October 16, 2009
Question

How to add custom property to CharacterFormat?

  • October 16, 2009
  • 4 replies
  • 4461 views

Hi,

Is there a way to add the custom property to character format and save in to XML TextFlow without significant changes in TLF?

This topic has been closed for replies.

4 replies

Participating Frequently
January 16, 2012

Now i've been trying to get my head around this for quite some time. I want to be able to use this with selections (range of elements) using ElementRange class doesn't seem to work tho because every getCommonContainerFormat etc is defining a new TextLayoutFormat so every custom values are ignored.

So i can save a value but everytime i try to recieve them it's gone.

Participating Frequently
January 12, 2012

Hi again!

This was to much of a challange for me to implement previously but now it's quite critical that i can do some custom values to the format of my textflow.

Has this changed annything since flex sdk 4.5? is it posible to extend TextLayoutFormat or add userStyle values to it?

The method of using ApplyElementUserStyleOperation is working but it gives me a warning that tells me it's deprecated and i don't know how to properly apply it for current selection (the way i can do with formats) and after that get from selection.

Participating Frequently
January 13, 2012

Looked into it, you are correct, from 2.0, ApplyElementUserStyleOperation is deprecated, for 3.0, you can uses ApplyFormatToElementOperation.

See reference here: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flashx/textLayout/operations/ApplyFormatToElementOperation.html 

Sample code:


var styleName:String = "userStyleName";          

var newStyleValue:String = "newUserStyleValue";               

var format:TextLayoutFormat = new TextLayoutFormat();               

format.fontSize = 10;               

format.setStyle(styleName,newStyleValue);               

ApplyFormatToElementOperation(textFlow.interactionManager.getSelectionState(), textFlow, format);

Participating Frequently
November 7, 2011

Sorry for digging up somethin old, but i am curios on how to add custom value to a selected section of textflow. How excactly does this ApplyUserStyleOperation works? some code examples would be greatly appriciated. I am looking for a way to apply CMYK values onto a selection of text much like i do with regular TextLayoutFormat and setFormatOfRange for RichEditableTextfield.

Tilly

Participating Frequently
November 8, 2011

Hi Samuel, 

Hope below code helps, it shows how to use ApplyElementUserStyleOperation to apply user styles. 

var styleName:String = "userStyleName";

var origStyleValue:* = textFlow.getStyle(styleName);

var newStyleValue:String = "newTFStyleValue";

var editManager:EditManager = new EditManager();

textFlow.interactionManager = editManager;

ApplyElementUserStyleOperation(editManager.getSelectionState(),textFlow,styleName,newStyleValue));

October 16, 2009

It would be helpful to have a little more information about the type of property you'd like to add, but you should be able to do something like that with user styles on the flow elements.

Adobe Employee
October 16, 2009

I'm going to echo Brent's suggestion. I'd suggest looking at the ApplyElementUserStyleOperation -- create one and then call editManager.doOperation with it. Sorry, there ought to be a method for it on the EditManager, but you can do it yourself with just this small extra step. Note that the API for this is different from applyFormat, because with this you specify the actual element it applies to. In your case, this might always be the leaf node, but the API allows you to add at any of the FlowElement hierarchy.

- robin

Known Participant
October 16, 2009

Wow, this is exactly what I was looking for!

I still have 2 questions, I'm a bit confused of:

1) Why does "value" argument of ApplyelementUserStyleOperation constructor is int? I guess small mistake is in the document (http://help.adobe.com/en_US/Flex/4.0/langref/flashx/textLayout/operations/ApplyElementUserStyleOperation.html).

2) Why not to move userStyle directly to ITextLayoutFormat? Is this logically incorrect?

And another one question. I'm using Flex SDK 3.4 now. Shall I switch to Gumbo to get these nice userStyle features?

Thanks again! You helped me a lot!