Skip to main content
February 15, 2011
Question

How to get a custom style value in the interaction manager's getCommonCharacterFormat() function ?

  • February 15, 2011
  • 1 reply
  • 398 views

Hi,

I have a scenario where I have applied Css styles to the textflow using the IFormatResolver interface.

Now what I need is a way  to show which style is applied to the current selection.

I am getting all infomation using the following however the style name that is associated is not there.

var textLayoutFormat:TextLayoutFormat = textFlow.interactionManager.getCommonCharacterFormat() as TextLayoutFormat;

in my case I am having a parameter myStyle in the usersstyle object of the actual flow elements, but when I do the above I find that the user style object is different and it doesnt have any parameters as mystyle under it

-Ashar

This topic has been closed for replies.

1 reply

Adobe Employee
February 15, 2011

There's no general code for that.  You will have to write something on your own.  If for example you want to check for a specific style having a common value across the range a new function modeled on getCommonCharacterFormat would work:

    public static function getCommonCharacterStyle(range:ElementRange,styleName:String):*
    {       
        var leaf:FlowLeafElement = range.firstLeaf;
        var value:* = leaf.getStyle(styleName);
        if (value === undefined)
            return undefined;    // no common value or common value is undefined
       
        for (;;)
        {
            if (leaf == range.lastLeaf)
                break;
            leaf = leaf.getNextLeaf();
            if (value !== leaf.getStyle(styleName))
                return undefined;    // no common value
        }
       
        return value;     // common value
    }

Depending on your use case some variation of this will supply the information your application needs.  More complicated, but doable, would be extending this to work on all userStyles in leaf returning an object of key-value pairs.

Hope that helps,

Richard