Textfield Overflow In AS2

How to make text overflow from one field to the next

One of the things lacking in Flash is the fact that it's one of the only programs in the Adobe suite that doesn't support text overflow into other text boxes. In an effort to work around it, I've managed to develop some AS2 that works - sort of. It's kind of a hack-y way to achieve the result one is looking for, but it seems to work for the most part. The code is as follows:

theString = "";
fontSize = 12 + 2; // [size] + [line spacing]
approxCharWidth = 34; // Characters per line
approxChar = tbox1._height/fontSize*approxCharWidth;
tbox1 = theString.slice(0,approxChar);
tbox2 = theString.slice(approxChar, theString.length);

Now, let's take this line by line:

1. theString = "";

This line defines the string, or the text that you're cutting up into the two boxes.

2. fontSize = 12 + 2;

This is a lie. The font size is not actually 14, it's 12. It's the font size, plus the line spacing of the paragraph.

3. approxCharWidth = 34;

This is the amount of characters that will fit width-wise in your text box. I figured this out simply by typing a bunch of 0's until it went to the next line, then counted them. You might want to be a little conservative with this number, as if it is too big, some of the content will go missing.

4. approxChar = tbox1._height/fontSize*approxCharWidth;

In order to find out where to chop the string, we need to figure out approximately where the last character would be. This takes the height of the box, translates it into the number of lines and multiplies it by the number of characters per line. It uses the same principle as length*width=area.

5. tbox1 = theString.slice(0,approxChar);

String.slice is a function used to take a chunk out of a string. In this case, we're defining the contents of text box 'tbox1' as the chunk that begins at character number '0' and ends at our approxChar number - which should be near the end of the text box.

6. tbox2 = theString.slice(approxChar, theString.length);

Finally we take the remainder of the string by starting where we left off in the previous line - at approxChar - and end with the very last character, which would be the same number as the length of the string. Not so bad, huh? If you're still having problems, send me an email and I'll see what I can do for you. Hope you enjoyed the tutorial.



Posted by Adam on 25.02.2009.



Our Links

North43 Design
Our Latest
Client Login
Terms of Use

Categories

View All
News
Samples
Tutorials

Archive

This Month
Last Month
March 2009
February 2009
January 2009
CLIENT LOGIN | HOME | PROMOTIONS | PORTFOLIO | BLOG | CONTACT
info@north43design.com - All Content © 2008 North43 New Media Design