Skip to main content
June 21, 2009
Question

Possible regression moving from build #452 to #455

  • June 21, 2009
  • 1 reply
  • 588 views

this works in build 452, but not anymore in 455, i'm trying to change the color of clicked words to red.

am I doing anything wrong?


...

... // create text flow, with paragraph and spans in it

...

_textFlow = new TextFlow();

var p:ParagraphElement = new ParagraphElement();

span.tlf_internal::getEventMirror().addEventListener(MouseEvent.CLICK, tfmo); // to enable regions

var span:FlowElement;

span = new SpanElement();

(span as SpanElement).text = "hello"

span.format = ef;  // ef is some TextLayoutFormat I created earlier

span.setStyle("wordObject", currWord);

span.tlf_internal::getEventMirror().addEventListener(MouseEvent.CLICK, tfmc); // to enable regions

p.addChild(span);

_textFlow.addChild(p);

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

_textFlow.flowComposer.addController(cc);

_textFlow.addEventListener(CompositionCompletionEvent.COMPOSITION_COMPLETE, onCompositionComplete);


_textFlow.flowComposer.updateAllControllers();

...

...

...

private function tfmc(event:MouseEvent):void

{

// LOCATE THE REGION

var line:TextLine = event.currentTarget as TextLine;

var tfl:TextFlowLine  = line.userData;

var atomIdx:int = line.getAtomIndexAtPoint(event.stageX, event.stageY);

var rec:Rectangle = line.getAtomBounds(atomIdx);

var regions:Vector.<TextLineMirrorRegion> = line.mirrorRegions;

var theRegionIndex:int;

for (var i:int = 0; i < regions.length; i++)

{

     if (regions.bounds.intersects(rec))

     {

          theRegionIndex = i;

          break;

     }

}

var region:TextLineMirrorRegion = line.mirrorRegions[theRegionIndex];

trace(region.element.text);


// GOT THE REGION, CHANGE TEXT ELEMENT COLOR TO RED

var el:ContentElement = region.element;

var newEl:ElementFormat  = region.element.elementFormat.clone();

newEl.color = 0xff0000;

el.elementFormat = newEl;


_textFlow.flowComposer.updateAllControllers();

}              

This topic has been closed for replies.

1 reply

Adobe Employee
June 22, 2009

So the reason this worked at all is there was a bug in TextFlow.isDamaged.  It was always returning true even after an update.  That's been fixed.  Fixing it has caused your event handler to no longer recompose.

What you are doing is directly modifying the FTE objects out from underneath the TLF code.  This is guaranteed not to work reliably.  TLF is managing the FTE objects based on its properties.  In your code you directly modified the FTE properties and they are now getting out of sync.  If any TLF property is changed on that Span or its parents your color change will be lost.  Instead of modifying the FTE object color I recommend finding the corresponding SpanElement and modifying that.  Its at _textFlow.findLeaf(tfl.getAbsoluteStart+atomIdx) (something like that).

FWIW the isDamaged fix had a bad (unrelated to this code) side effect in the scrolling code.  TLF doesn't put all the lines on the display list for performance reasons.  The isDamaged bug was letting compose run during a scroll and correctly putting the lines on.  Once the bug was fixed a scrolling bug was exposed but not caught till after build 455.  I changed isDamaged to always return true on the last container if scrolling is on.  A better solution is needed but that works for now.  So your immediate bug may go away but all attribute changes need to be done on the TLF model which manages the FTE objects.

Best Regards,

Richard