Skip to main content
Participant
April 11, 2011
Answered

What's the best way to detect that text fits into ContainerControllers without scrolling?

  • April 11, 2011
  • 1 reply
  • 679 views

Hi.

Question

What's the best way to detect that text typed by user (or added programmatically) exceeds available container space and find out where starts truncated part? Is there available some other (than described bellow) easy way to detect it or disallow set of controllers to receive more characters that can be displayed in given composition area?

My partialy failed attempt (simplified)

For example lets say that I've got an editable textflow with attached two instances of ContainerController.


var flow:TextFlow = createSomeFlowFromGivenString(sampleText),

    firstController = new ContainerController(firstSprite, 100, 30),

    lastController = new ContainerController(secondSprite, 600, 30);

flow.interactionManager = new EditManager(new UndoManager());

flow.flowComposer.addController(firstController);

flow.flowComposer.addController(lastController);

flow.flowComposer.updateAllControllers();

With enabled vertical scroll policy I can compare height of the composition in last controller with height of the content:

var bounds:Rectangle = lastController.getContentBounds(),

    overflow:Boolean =  lastController.compositionHeight < bounds.height;

trace('Content does not fit into given area?', overflow)

But when I switch vertical scroll policy off (lastController.verticalScrollPolicy = ScrollPolicy.OFF) - unfortunately this no longer works...(In my case scrolling should be dissabled, since text areas might have only one line with restricted width)

Use case

I want to create fillable form. Field might have a single or multiple lines. One field might start in the middle of the page, continue in the next line where it spreads through whole page and end in the - quarter of page width long  - third line. Text typed by the user can't exceed given area since it might cover some static text that sits right after/below field.

Something like ascii image bellow:

-------------------------------------------- |                <PAGE>                    | |                                          | |                                          | |                                          | |               [Field starts here........ |  | ........................................ | | ........................................ | | Ends here..]                             | |                                          | |                                          | | [Another field] xxxx  xxxx xxxxxxxx x xx | | xxxxxxxxxxxxxxxxxxx                      | |                                          | |                              [One more.. | | .....]                                   | |                                          | |                                          | |                                          | |                                          | |                                          | |                                          | |                                          | |                                          | --------------------------------------------

Info:

[......]  <-- form fields starts with '[' character, and ends with ']' xxx       <-- sample, static text | and _   <-- page borders

This topic has been closed for replies.
Correct answer zhen_bian

If you want to detect the overflow in last container, there's another thread discussed it before.

http://forums.adobe.com/thread/795264

You can detect it with "lastContainerController.absoluteStart+lastContainerController.textLength < textFlow.textLength".

1 reply

zhen_bianCorrect answer
Participant
April 12, 2011

If you want to detect the overflow in last container, there's another thread discussed it before.

http://forums.adobe.com/thread/795264

You can detect it with "lastContainerController.absoluteStart+lastContainerController.textLength < textFlow.textLength".

antiflowAuthor
Participant
April 12, 2011

I've tried something like that previously, but it didn't work because then I've got vertical scroll policy to set to 'auto'. After changing verticalScrollPolicy to ScrollPolicy.OFF  in the last container it worked like a charm.

Thanks zhen bian