TextFlowPro enables you to flow a series of text fields together so that they act as a single text container, and still allow users to select, edit, and copy/paste text between the textfields. It should work with any text formatting, including different text formatting on different fields. It even supports tabIndex.

In terms of the sheer number of problems I had to solve to get things working, this is one of the most complex classes I have released for free. I was originally going to release this as a commercial component alongside the Spelling Plus Library, but I never got it to a level of quality that I was happy with. While I think I could iron out the remaining bugs, I still don't think it would reflect the quality I want our commercial offerings to show - there are simply too many player bugs, edge cases, and niggling user experience problems.

However, it represents a huge amount of work, and I didn't want to just leave it to rot, so I'm releasing it in the hopes people can do really cool things with it. At the very least, I hope it serves as a crash course in working with some of the text metrics APIs in player 9. I'm more than happy to answer any questions about how it works in the comments below.

Here are a couple of simple demos to show what it can do. These will be familiar to you if you've checked out TextFlowLite or TextFlow, but these add one small thing: editing!

The first demo shows TextFlowPro being used for a dynamic multicolumn layout. Note that you can select, edit, copy/paste, navigate, and tab out of / into the text flow. You can even make a selection and have that selection remain intact as you resize the columns.

The second demo shows TextFlowPro being used to fit text to a shape. It's flowing text between 21 textfields, spread between the 7 ornament clips. As with the demo above, you can select, edit, navigate, etc within the text as though it were a single text field. Also, in this demo a tabIndex was assigned to the text flow so that you can tab into and out of it.

I don't have the time right now to fully document this class, but I think the usage is fairly straightforward. Here's a quick overview:

// instantiation:
var flds:Array = [fld1,fld2,fld3] ;
var myTFP:TextFlowPro = new TextFlowPro(flds , text); // note that it will use the text from the first field if the second parameter is omitted.

// methods:
myTFP.reflow(); // forces reflow, ex. if you resize a textfield
myTFP.setSelection(beginIndex:uint, endIndex:uint); // focuses and sets selection (similar to TextField method)
myTFP.clearSelection(); // removes selection and focus
myTFP.getOverflow(textFieldIndex:int=-1, ltrimString:Boolean=true); // returns the text that overflows (goes beyond) the specified field index, -1 for overflow of last field

// properties:
myTFP.alwaysShowSelection:Boolean; // similar to TextField property
myTFP.type:String; // similar to TextField property
myTFP.text:String; // sets text to display in the text flow
myTFP.selectionBeginIndex:int; // Read-Only, similar to TextField property
myTFP.selectionEndIndex:int; // Read-Only, similar to TextField property
myTFP.tabIndex:int; // similar to TextField property
myTFP.textFields:Array; // array of textFields to flow text through
myTFP.orphans:uint; // minimum lines left at the start of a field
myTFP.widows:uint; // minimum lines left at the end of a field

There are also a few known issues:

  • orphans doesn't seem to be working properly.
  • problems with setting the caret to the end of a line or on an empty line.
  • caret draws at end of last textfield if there is an overflow.
  • up/down arrow behaviour is (understandably) weird.
  • double click to select word doesn't work.
  • right click menu operations don't work (and probably never will).
  • it has definitely not been tested, cleaned up, or optimized sufficiently (or really at all).

If enough people plan to use this class for something real, I might take the time to address these. I already have a pretty good idea as to how to fix most of them, but I don't want to run the text API gauntlet if this is just going to be an interesting experiment that won't see real use.

As usual, I am releasing TextFlowPro under MIT license. However, I would really appreciate hearing about what people do with it, and receiving credit where possible if you use it in your work. I kind of feel like a proud pappa releasing my child into the world, and hoping she will write back occasionally. :)

You can download TextFlowPro, with the demos above by clicking here.