Skip to main content
Known Participant
October 22, 2009
Answered

[Novice Problem] With CharacterFormat

  • October 22, 2009
  • 2 replies
  • 688 views

Hi everybody,

I am working with TLF for few days and I don't understand something...
I have created a textflow, and I want to apply a style (color, fontFamily...) on selected characters

But when I use CharacterFormat, the style is applied on all the text.


My first try (juste change the colortext) :
Here I create my textflow :

private var _textFlow:TextFlow = null;
               
private var _container:Sprite = null;
               
public var manager:EditManager;

private function initNote():void
               
{
                       
var controller:IContainerController;
               
                        _container
= new Sprite();
                        textArea
.rawChildren.addChild(_container);
                        _textFlow
= new TextFlow ();
                       
                        controller
= new DisplayObjectContainerController(_container,textArea.width,textArea.height);
                        _textFlow
.flowComposer.addController(controller);

                        _textFlow
.addEventListener(StatusChangeEvent.INLINE_GRAPHIC_STATUS_CHANGED, graphicStatusChangeEvent);
                       
                        manager
= new EditManager(new UndoManager());
                        _textFlow
.interactionManager = manager;
                       
                        _textFlow
.interactionManager.setSelection(0,0);
                       
                        _textFlow
.flowComposer.updateAllContainers();
                        _textFlow
.interactionManager.setFocus();
               
}
               



Here, I want to apply the selected color

private function changeCharacterColor(event:ColorPickerEvent😞void
{
                       
var cf:CharacterFormat = new CharacterFormat(currentNote.myTextFlow.characterFormat);
                       
                        cf
.color = colorChar.value;
                        currentNote
.myTextFlow.characterFormat = cf;
                        currentNote
.myTextFlow.flowComposer.updateAllContainers();
               
}

I checked  the selection to be sure that it is good (thanks to the TextScrap options). But no problem on this side.

I try today with myTextFlow.interactionManager.selectionState.pointFormat = cf to apply the new color. But it doesn't work too.

I think I have miss something. Can somebody help me?

Thank you very much.

NB: Sorry for my bad english 😕😕 (poor french I am )

This topic has been closed for replies.
Correct answer rdermer

Please get a more recent build.  It will work fine with Flex SDK 3.2.

I think you should look at the example code to see how formatting is applied to a range.  There is an editor included.

Examples are here:

http://opensource.adobe.com/wiki/display/tlf/Text+Layout+Framework

The latest TLF is available from the "Download Flex SDK" link on that page.

Regards,

Richard

2 replies

Known Participant
October 26, 2009

Hi Richards,

Thank you very much for your response.

It's very easy to apply a format for a character's selection in the latest build of TLF.

I don't know why but I was thinking that with a 3.2 SDK, I could'nt use the lastest version of TLF.

I install the last build and everything run correctly.

Thank you very much !

And sorry for this novice question :/

See you soon

Known Participant
October 23, 2009

Any idea?

I work with sdk 3.2, (it's an AIR application), ad the FP 10.

I saw that I have the old version of TLF : http://livedocs.adobe.com/labs/textlayout/flashx/textLayout/events/SelectionEvent.html

and note this one : http://help.adobe.com/en_US/Flex/4.0/langref/flashx/textLayout/events/SelectionEvent.html

Do you know if I can use the TLF Build 370 with my sdk 3.2 ? If it's yes what have I to do?

If I can't use the latest version of TFL :

My actual problem is (I am still working on the style of selected character :'( )  in my version of TLF with a SelectionEvent, I just can use

event.selectedElementRange because the event.selectionState doesn't exist. Do you know how to have the selectionState corresponding?

private function addListenerTextFlow(e:FlexEvent):void
        {
            myTextFlow.addEventListener(SelectionEvent.SELECTION_CHANGE, handleSelectionCharacter);
        }
       
        public function handleSelectionCharacter(event:SelectionEvent):void
        {
            this.noteOptions.myNoteOptionsCharacter.selectedRange = event.selectedElementRange;

this.noteOptions.myNoteOptionsCharacter.selectionState = ???? ;
            this.noteOptions.myNoteOptionsCharacter.cf = new CharacterFormat;
        }

and when I apply a style :

private var selectedRange:ElementRange;

private var selectionState: SelectionState

private function changeCharacterFont(event:ListEvent):void
        {   
           
            cf.fontFamily = fontList.value.toString();
            (currentNote.myTextFlow.interactionManager as EditManager).applyCharacterFormat(cf, selectionState);
            currentNote.myTextFlow.flowComposer.updateAllContainers();
   
        }

As you can see to apply my font it is missing the arg2 (selectionState), but I have an ElementRange. Can I "transform" an ElementRange into a SelectionState?

Please, I need your help :'(

rdermerCorrect answer
Adobe Employee
October 23, 2009

Please get a more recent build.  It will work fine with Flex SDK 3.2.

I think you should look at the example code to see how formatting is applied to a range.  There is an editor included.

Examples are here:

http://opensource.adobe.com/wiki/display/tlf/Text+Layout+Framework

The latest TLF is available from the "Download Flex SDK" link on that page.

Regards,

Richard