Skip to main content
Known Participant
May 26, 2010
Question

How to apply text formatting immediately?

  • May 26, 2010
  • 1 reply
  • 614 views

Hello!

I apply text formatting to the empty newly created text flow. It seems to be strange that the formatting is not applied immediately, but when I start editing.

The small sample demonstrates the problem.

<?xml version="1.0" encoding="utf-8"?>

<mx:Application

xmlns:mx="http://www.adobe.com/2006/mxml"

layout="

vertical"

creationComplete="onCreationComplete()"

>

<mx:Script>

<![CDATA[

import flashx.textLayout.events.FlowOperationEvent;

import flashx.textLayout.formats.ITextLayoutFormat;

import flash.text.engine.RenderingMode;

import flash.text.engine.FontLookup;

import flashx.textLayout.formats.TextLayoutFormat;

import mx.controls.SWFLoader;

import flashx.textLayout.edit.EditManager;

import flashx.textLayout.container.ContainerController;

import flashx.textLayout.elements.TextFlow;

private var textFlow:TextFlow;

private function onCreationComplete():void {

var container:Sprite = new Sprite();

canvas.rawChildren.addChild(container);

var containerController:ContainerController = new ContainerController(container, canvas.width, canvas.height);

textFlow=

new TextFlow();

textFlow.flowComposer.addController(containerController);

textFlow.interactionManager=

new EditManager();

textFlow.flowComposer.updateAllControllers();

}

private function onClick():void {

var charFormat:TextLayoutFormat = new TextLayoutFormat();

var containerFormat:TextLayoutFormat = new TextLayoutFormat();

var paragraphFormat:TextLayoutFormat = new TextLayoutFormat();

charFormat.fontSize=36;

textFlow.interactionManager.selectAll();

(textFlow.interactionManager

as EditManager).applyFormat(charFormat, paragraphFormat, containerFormat);

textFlow.interactionManager.refreshSelection();

textFlow.flowComposer.updateAllControllers();

}

]]>

</mx:Script>

 

<mx:Canvas id="canvas"

width="

200"

height="

200" borderStyle="solid"/>

<mx:Button id="button"

label="

Push me"

click="onClick()"

/>

</mx:Application>

When you click the button new font size is set. But the cursor in text field is not changed to a bigger one until I start editing. Also if to look at the textFlow internals in debugger you can see that new font size is not set...

How can I force this?

Kind Regards

This topic has been closed for replies.

1 reply

Adobe Employee
May 26, 2010

This is arguably a bug with a few things conspiring to cause the problem.  The general idea is that each paragraph ends with a paragraph terminator and the final terminator isn't selectable - that seems to be the core of the problem.  The other conspirator is that with a point selection character level format changes aren't applied until the next character is entered.  So with an empty document you always have a point selection. I could see character level format changes applying instantly to empty paragraphs.  I'll file a bug for more investigation.

As for workarounds - well there's always direction model calls - just set the format directly on the span.  Another possibility would be to detected exactly this case and insert a character and then undo it.

Note in your sample code the refreshSelection and updateAllControllers calls after applyFormat are redundant and can be safely removed.  Also any of the formats passed to applyFormat can be null.

Hope that helps,

Richard

Known Participant
May 27, 2010

Richard, thank you very much both for proposed workaround and usefull advises to remove refreshSelection and updateAllControllers.