views:

235

answers:

1

There's only room for three lines of text in the interface, but the content is external and variable, and if it ends up taking up more than three lines, there needs to be some sort of 'view all' button functionality. I can kind of think about what that function needs to look like, but I'm not quite sure what the best way to do it in AS3 would be. Something like (in pseudo code):

function cropText(source:TextField, length:int, append:String):TextField{
    if(source.lineCount > length){
        source.text = // magic function that retuns the first length lines,
        // minus append.length characters, with the append value tacked onto the end
    }
    return source;
}

... right? How would you fill in the missing bit?

+1  A: 

Something like...

private function cropText(source:TextField, length:int, append:String):TextField {
    if (source.numLines > length) {
        source.text = source.text.substr(0, source.getLineOffset(length) - append.length) + append;
    }

    return source;
}
MrKishi
Yesss, getLineOffset was the missing puzzle piece. thanks!
matt lohkamp