Tue 30 Mar 2010
Abbreviate TextField Characters According to Rows Count
Posted by luar under Flash , WorksNo Comments
Before AS3, we can only use substr to abbreviate string characters number for TextField, but we have to guess a extract number to fit our UI design, e.g. only show two lines, we have to guess in this font size, font face, what is maximum numbers of character can be shown. It is a problem which is hard to solve for a long time.
When come to AS3, TextField class have a new method call getLineLength(), it can return each line, number of characters are shown. So I have written this small class to help me limit the number of rows can be shown in TextField
Download MaxRowsTextField class file
Download demo source
Usage
This class is extended from TextField class:
tf.width = 290;
tf.multiline = tf.wordWrap = true;
// 0 mean unlimited, default is 0
tf.maxRows = 4;
// change abbreviate symbol, default is "…"
tf.moreStr = "…(more) ";
// if you want to limit rows count, use this, otherwise, you can just use text or htmlText
tf.text2 = "This is a vey long message";
This class is extracted and simplified from my VCASMO 2.0 project.


