01
Apr 10

Truncating Text

Here’s a code snippet that takes a textfield and checks to see if its text is too long to fit in the textfield. If it is, it truncates the text and adds an ellipsis (that’s three dots to you) to indicate that the text has been truncated.

function truncateText(textField:TextField):void {
    var text:String = textField.text;
    while (textField.maxScrollV > textField.scrollV) {
        text = text.substring(0, text.length - 1);
        textField.text = text + "...";
    }
}
Copyright © 2012 The Daily Flash
Proudly powered by WordPress, Free WordPress Themes, and Linux Hosting