JTtheGeek
JTtheGeek

Reputation: 1713

applying formatting to a character range in textflows in Flex 4.10 SDK

When using any version of Flex 4.10 SDK the following code apply's the format to an entire paragraph instead of a specific character range.

https://issues.apache.org/jira/browse/FLEX-33791

<?xml version="1.0"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" creationComplete="OnCreationComplete(event)">
    <s:TextArea width="100%" height="100%" id="txt" editable="true">
        <s:content>
            Lorem ipsum dolor sit amet, consectetur adipiscing elit.<s:br/>
            Vivamus eu erat ac est ullamcorper egestas eget nec mauris.<s:br/>
        </s:content>
    </s:TextArea>

    <fx:Script><![CDATA[
        import flashx.textLayout.edit.EditManager;
        import flashx.textLayout.formats.TextLayoutFormat;

        import mx.events.FlexEvent;

        private function OnCreationComplete(event:FlexEvent):void
        {
                var objFormat:TextLayoutFormat = new TextLayoutFormat();
                objFormat.backgroundColor = 0xB9CCFF;
                txt.selectRange(5, 8);
                var objManager:EditManager =  txt.textFlow.interactionManager as EditManager;
                objManager.applyFormat(objFormat, objFormat, objFormat);
        }

        ]]></fx:Script>
</s:Application>

Upvotes: 0

Views: 155

Answers (1)

Anthony Compton
Anthony Compton

Reputation: 5361

The three parameters for applyFormat are for three different ways the format can be applied.

The first parameter, "leafFormat" will get applied to LeafElement objects like SpanElement (or nodes, if you prefer to think of the XML that TLF generates) and will actually create a new leaf if the current (or supplied) SelectionState doesn't encompass an entire LeafElement.

The second parameter, "paragraphFormat" will get applied to the entire paragraph that the current (or supplied) SelectionState is a part of. So if I select only a few characters from a paragraph and then call applyFormat, passing in a background color for the "paragraphFormat" parameter, the entire paragraph will get the background color.

The third parameter, "containerFormat" I've never used and haven't really looked into at all. I would guess that it applies the format to the entire ContainerController object that helps lay out the text.

You can safely pass null (or completely different formats) in for any of the four parameters.

So, in short, I think to fix your problem you just change you function call to:

objManager.applyFormat(objFormat, null, null);

Upvotes: 2

Related Questions