Copy link to clipboard
Copied
I have a bunch of linked containers which I am flowing text through. How can I detect when the text has filled a container? there's an overflowPolicy so I assume this can be detected.
1 Correct answer
Hi,
I used this :
private function IsOverset(textFlow:TextFlow):Boolean
{
var zeComposer:IFlowComposer=textFlow.flowComposer;
var iTextLen:int=textFlow.textLength;
var iNoController:int=zeComposer.findControllerIndexAtPosition(iTextLen - 1);
return (iNoController == -1);
}
HTH,
J.
Copy link to clipboard
Copied
Hi,
I used this :
private function IsOverset(textFlow:TextFlow):Boolean
{
var zeComposer:IFlowComposer=textFlow.flowComposer;
var iTextLen:int=textFlow.textLength;
var iNoController:int=zeComposer.findControllerIndexAtPosition(iTextLen - 1);
return (iNoController == -1);
}
HTH,
J.
Copy link to clipboard
Copied
Hey! That might just work! thanks for your response.
🙂
Copy link to clipboard
Copied
short lived I'm afraid. I only ever get -1 with this ...
var containerIndex:int = textFlow.flowComposer.findControllerIndexAtPosition(textFlow.textLength);
if(containerIndex==-1) textFlowCompleteHandler();
I'm detecting this as the flow is created. The textFlow.length is being set correctly.
Any ideas?
Copy link to clipboard
Copied
So I fixed that issue ...
var containerIndex:int = textFlow.flowComposer.findControllerIndexAtPosition(textFlow.textLength-1);
if(containerIndex==-1) textFlowCompleteHandler();
... by using textLength-1 to give me the last character in my flow.
BUT it now doesn't give me -1 ever. Even when the text has flown through the last container. I guess my container is still being used by the flow. Do I need to set the container so it doesn't allow scrolling or something like that?
Copy link to clipboard
Copied
I'd do this a different way. Not exactly what you want but similar. This code adds containers until all the text in the TextFlow belongs to some container.
for (;;)
{
var controller:ContainerController = textFlow.flowComposer.getControllerAt(textFlow.flowComposer.numControllers-1)
if (controller && controller.absoluteStart+controller.textLength == textFlow.textLength)
break; // ALL DONE
controller = new Controller(new Sprite,somewidth,someheight)
// turn off scroll policy else all overflow text goes in the last container
controller.verticalScrollPolicy = controller.horizontalScrollPolicy = ScrollPolicy.OFF;
textFlow.flowComposer.addController(controller);
textFlow.flowComposer.updateAllControllers();
}
Didn't compile this but I just wrote something similar (its on a different machine that I can't get to right now).
Also reccomend getting TLF 1.1 for this algorithm as its much more efficient for this type of thing than TLF 1.0.
Hope that helps,
Richard
Copy link to clipboard
Copied
Yes, if my memory is right, you need to disable scrolling in the container. Otherwise, the whole text will flow in the container and there will never be an overflow of course...
I used this when adding controller :
var
aCC:ContainerController=new ContainerController(aFrame.zeSprite, iCW, iCH);aCC.verticalScrollPolicy=
'off';
Maybe some problems may occur because of possibly asynchronous composition (but I'm not really sure).
J.
Copy link to clipboard
Copied
I've just tested this and you're correct. I set the Scrollpolicy to OFF for
all my controllers and now when I run this code after each FlowElement
object is created and added to my TextFlow it will detect when the element
is no longer within a container ...
var containerIndex:int =
textFlow.flowComposer.findControllerIndexAtPosition(textFlow.textLength-1);
if(containerIndex==-1) textFlowCompleteHandler();
Thanks for the help guys.
Also, I found that this ...
config.overflowPolicy = OverflowPolicy.FIT_DESCENDERS;
... now works as expected. Before I set the scroll policy to OFF the last
line of my flow was cut off at the bottom of the container.
