Skip to main content
Known Participant
September 15, 2010
Answered

CompositionHeight issues

  • September 15, 2010
  • 3 replies
  • 2301 views

Hi,

I have a container that resizes when the user modifies its content. This textflow may contain text and images. I need to find a way to measure the total height required to display its content. I have read several post here and have tried several solutions without luck.

I'm waiting to the CompositionCompleteEvent event and then trying to figure out of the container needs to be resized:

protected function compositionCompleteHandler(event:CompositionCompleteEvent):void

{

     var containerIndex:int = event.textFlow.flowComposer.findControllerIndexAtPosition( event.textFlow.textLength-1 );

     if(containerIndex == -1){

               // resize the component!!!!!

               var boundaries:Rectangle = (textFlow.flowComposer.getControllerAt(0) as ContainerController).getContentBounds();

               textFlow.flowComposer.composeToPosition();

               boundaries = (textFlow.flowComposer.getControllerAt(0) as ContainerController).getContentBounds(); // boundaries.height outputs the same value, no change

        }

}

The weird thing is tha after doing composeToPosition(), there is no change.

Also, if in the second line of the text, there is an image, the bounds don't use the space used by the image to calculate the bounds. why???

Any ideas?

This topic has been closed for replies.
Correct answer injpix

Thanks for the update.

I think I'm missing something else. I'm reviewing compositionHeight and getContentBounds().height in the CompositionComplete hander and in the on Enter Frame listener added on Damage Events, and I get the exact same values. Also, this is happening in both cases with and without images.

Any ideas?


What code is in your Damage event handler?  Below is mine, I can't remember why I am only listening to it once, but I am sure there is or was a reason.

private function onDamageHandler(event:DamageEvent):void
{
     textFlow.removeEventListener(DamageEvent.DAMAGE, onDamageHandler);

     textFlow.flowComposer.updateAllControllers();
}

3 replies

storm767Author
Known Participant
September 16, 2010

I'm trying to find out if the problem is trying to ge the height before the model is done with his work, and it looks like that's not the issue:

I added an event listener to the mouse down event, and I get the exact same values:

private function onMouseOverContainerMove(event:MouseEvent):void

{

     trace('(DOWN) compositionHeight 1: ' + (textFlow.flowComposer.getControllerAt(0) as ContainerController).compositionHeight + ' x ' + (textFlow.flowComposer.getControllerAt(0) as ContainerController).compositionWidth);

     trace('(DOWN) boundariesHeight 1: ' + (textFlow.flowComposer.getControllerAt(0) as ContainerController).getContentBounds().height);

}

I refuse to think that it's so complicate or imposible for TLF to measure the content of a TextFlow, but can find any solution. Ideas, please...

Inspiring
September 16, 2010

You mentioned in some textflows there are images; do you have ILG handlers for them?  If so, are you calling updateAllControllers()?

storm767Author
Known Participant
September 16, 2010

I'm trying to test both scenarios, with only text and text and images. Yes, I'm calling updateAllcontrollers:

private function imageLoaded(event:StatusChangeEvent):void

{

     var parenttextFlow:TextFlow = event.currentTarget as TextFlow;

     parenttextFlow.flowComposer.updateAllControllers();

}

The problem is that I don't know how to measure the height. it always returns the same value.

Inspiring
September 16, 2010

As robin.briggs mentioned, listening for a Damage event may be beneficial.

Currently I am adjusting the composition height via container.setCompositionSize() and I am seeing results that are unexpected.  I also have images in my flow and when my ILG (InlineGraphicElement) handler gets called I have to do some funky stuff for the height to be adjusted as desired.  Below is my ILG handler.

protected function onILGChangedHandler(event:StatusChangeEvent):void
{
     var newHeight:int = Math.ceil(container.getContentBounds().height);    
     if(newHeight>0)
          container.setCompositionSize(this.width, newHeight);
    
    
     textFlow.flowComposer.updateAllControllers();    
    
    
     var secondNewHeight:int = Math.ceil(container.getContentBounds().height);
     if(newHeight != secondNewHeight)
     {
          container.setCompositionSize(this.width, newHeight+secondNewHeight);
         
          textFlow.flowComposer.updateAllControllers();
     }
}

So by adding the 2 height variables and passing it to setCompositionSize, the composition height is adjusted perfectly.  I am also listening for a DamageEvent, but then I remove its listener after the first time it is called.  Does anyone know if this is normal behavior?  I am using Flex 4.1 with TLF 1.1.

Adobe Employee
September 16, 2010

You might try listening for the damage event instead. I think you can't compose from inside the Composition CompleteHandler because its a nested call into composition. But you could listen for the DamageEvent, and when you get one add a listener for the ENTER_FRAME event. On the enter frame event, you can recompose and reset the height and remove the enter frame listener. That will enable you to group multiple damage events together, and I think it will allow the recompose to happen correctly. That's what I'd suggest trying, anyway.

storm767Author
Known Participant
September 16, 2010

Hi Robin,

Thnks fo the answer.

Just one question.

Why do I need a Enter_frame event? is for waiting until the composition is ended?

I'm going to try it..

Adobe Employee
September 16, 2010

The enter frame event is for two reasons. First, we send out a damage events when they happen, so the model may not be a consistent state when you get one. Also, a single user action may result in several different model level changes, each one of which will have a damage event. If you tried to respond to each one, it would be very slow. By putting the processing off to the enter frame, you know the model is in a consistent state (i.e., its safe to compose) and you aren't composing for intermediate changes.

- robin