Skip navigation
Currently Being Moderated

How to add custom property to CharacterFormat?

Oct 16, 2009 1:13 AM

Hi,

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

 
Replies
  • Currently Being Moderated
    Oct 16, 2009 8:25 AM   in reply to Alexander Chingarev

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 16, 2009 11:27 AM   in reply to brent.arndorfer

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 16, 2009 4:00 PM   in reply to Alexander Chingarev

    Interesting.  Looks like that could maybe be an ASDoc bug or something else going on.  The actual implementation of the contructor for ApplyElementUserStyleOperation in my build of TLF looks like this:

     

    public function ApplyElementUserStyleOperation(operationState:SelectionState, targetElement:FlowElement, styleName:String, value:*, relativeStart:int = 0, relativeEnd:int = -1)

     

    I'm not sure how to answer #2, but my first thought is that there's a fairly good chance that whatever you end up using 'user styles' for will not be related to the actual formatting of the text.  It could be some sort of metadata that's completely abstract from how the text is formatted or represented visually, which is where the text layout format applies.  There are more technical reasons why it shouldn't be there also, but they're probably not worth the energy unless you really want to know.   ..and Robin would be a better person to comment on that also.

     

    I don't know what build of TLF (if any) is included in the Flex 3.4 SDK, but TLF does not have any dependencies on the Flex framework (or any particular version of it).  The only requirement is that you are targetting Flash Player 10 or above.  You can always download the latest (or a very recent) version of the TLF SWC's, RSL's, and source with the Flex 4 SDK from the Flex 4 download site at:

    http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 19, 2009 5:19 PM   in reply to Alexander Chingarev

    That's a good point.  I hadn't considered the fact that there isn't currently good support for applying a particular user style to an abitrary text range.

     

    The ApplyFormatOperation, which does that for TextLayoutFormat's, utilizes methods in the behind-the-scenes ParaEdit class to apply the format and perform any leaf-splitting that is required to be able to apply that format for any given absolute start/end positions in the text.  That ParaEdit class does not currently have support for doing the same thing with user styles, but you could probably leverage methods or approaches from it if you were to try to do it manually for user styles.  It should be fairly easy to create an ApplyUserStyleOperation or something like that to encapsulate that logic and support undo/redo....

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 21, 2009 1:33 PM   in reply to Alexander Chingarev

    Right now ApplyUserStyleOperation operates on a single element or a subset of that element.  To make it work across multiple elements in a selection I'd suggest using beginCompositeOperation, then ApplyUserStyleOperation for each element in the range that you wish to apply the user style to and then endCompositeOperation to bundle them all into one operation.  This would continue to treat ApplyUserStyleOperation as a simple atomic operation that can be composed into more complex operations.

     

    pointFormat having no way to hold on to userStyles is a bug.  I'll write it up.

     

    Thanks,

    Richard

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 7, 2011 12:35 AM   in reply to Alexander Chingarev

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 7, 2011 10:33 PM   in reply to Samuel Tilly

    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(),textFlo w,styleName,newStyleValue));

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 12, 2012 6:55 AM   in reply to Alexander Chingarev

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 12, 2012 10:53 PM   in reply to Samuel Tilly

    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/fla shx/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.getSelection State(), textFlow, format);

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 16, 2012 4:06 AM   in reply to Alexander Chingarev

    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.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points