Flash AS3:在 X 行处裁剪 TextField 内容,添加 '...'在最后

发布于 2024-08-28 12:46:29 字数 465 浏览 4 评论 0原文

界面中只能容纳三行文本,但内容是外部的且可变的,如果它最终占用超过三行,则需要某种“查看全部”按钮功能。我可以考虑一下该函数需要是什么样子,但我不太确定在 AS3 中实现它的最佳方法是什么。类似于(伪代码):

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;
}

...对吗?你将如何填补缺失的部分?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ゝ偶尔ゞ 2024-09-04 12:46:29

像...

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;
}

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文