Actionscript 3 文本字段高度

发布于 2024-12-10 12:34:48 字数 438 浏览 0 评论 0原文

我需要将文本字段自动调整大小属性设置为 NONE,以确保 HTML 链接不会在翻转时跳转。

但是,当我这样做时,如何设置文本字段高度属性以显示所有文本而不滚动?

我已经尝试了以下方法,但由于我无法弄清楚的原因,它挤压了我的文本高度:

htmlTextField.autoSize = TextFieldAutoSize.LEFT;   
htmlTextField.htmlText = htmlText;
var recordedHeight:Number = htmlTextField.textHeight;
htmlTextField.autoSize = TextFieldAutoSize.NONE;
htmlTextField.height = recordedHeight + htmlTextField.getTextFormat().leading + 1;

I need to set the text field autosize property to NONE to ensure that HTML links do not jump on rollovers.

However, when I do this, how can I set the textfield height property to show all of the text without scrolling?

I have tried the following but for a reason I cannot figure out, it's squishing the height of my text:

htmlTextField.autoSize = TextFieldAutoSize.LEFT;   
htmlTextField.htmlText = htmlText;
var recordedHeight:Number = htmlTextField.textHeight;
htmlTextField.autoSize = TextFieldAutoSize.NONE;
htmlTextField.height = recordedHeight + htmlTextField.getTextFormat().leading + 1;

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

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

发布评论

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

评论(2

画骨成沙 2024-12-17 12:34:48

文本字段具有 2px 装订线所以这可能会让你绊倒。

package
{
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;

    [SWF(frameRate="30", backgroundColor="#FFFFFF", width="500", height="500")]
    public class TextfieldHeight extends Sprite
    {
        public function TextfieldHeight()
        {
            var textFormat:TextFormat = new TextFormat();
            textFormat.size = 11;
            textFormat.font = "Georgia";

            var htmlTextField:TextField = new TextField();
            htmlTextField.setTextFormat( textFormat );
            htmlTextField.width = 250;
            htmlTextField.border = true;
            htmlTextField.wordWrap = true;
            htmlTextField.autoSize = TextFieldAutoSize.NONE; 
            htmlTextField.htmlText = '<a href="http://www.google.com">Lorem ipsum dolor</a> sit amet, consectetur adipiscing elit. Aliquam sodales, eros at convallis viverra, risus mauris euismod tortor, ac imperdiet sem augue vitae risus. Morbi ut sem neque. Vestibulum accumsan posuere augue, eu consectetur nibh porttitor eget. Sed suscipit sodales dui id pharetra. Vivamus quis hendrerit lectus. Vivamus interdum, felis a convallis dictum, libero erat aliquet massa, non placerat neque augue quis lacus. Aliquam viverra sem ultrices leo lacinia eu dignissim dolor ullamcorper. Etiam ullamcorper tincidunt velit, a vulputate sapien consequat quis.';
            htmlTextField.height = htmlTextField.textHeight + 4;

            this.addChild( htmlTextField );
        }
    }
}

TextFields have a 2px gutter all the way around so this may be tripping you up.

package
{
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;

    [SWF(frameRate="30", backgroundColor="#FFFFFF", width="500", height="500")]
    public class TextfieldHeight extends Sprite
    {
        public function TextfieldHeight()
        {
            var textFormat:TextFormat = new TextFormat();
            textFormat.size = 11;
            textFormat.font = "Georgia";

            var htmlTextField:TextField = new TextField();
            htmlTextField.setTextFormat( textFormat );
            htmlTextField.width = 250;
            htmlTextField.border = true;
            htmlTextField.wordWrap = true;
            htmlTextField.autoSize = TextFieldAutoSize.NONE; 
            htmlTextField.htmlText = '<a href="http://www.google.com">Lorem ipsum dolor</a> sit amet, consectetur adipiscing elit. Aliquam sodales, eros at convallis viverra, risus mauris euismod tortor, ac imperdiet sem augue vitae risus. Morbi ut sem neque. Vestibulum accumsan posuere augue, eu consectetur nibh porttitor eget. Sed suscipit sodales dui id pharetra. Vivamus quis hendrerit lectus. Vivamus interdum, felis a convallis dictum, libero erat aliquet massa, non placerat neque augue quis lacus. Aliquam viverra sem ultrices leo lacinia eu dignissim dolor ullamcorper. Etiam ullamcorper tincidunt velit, a vulputate sapien consequat quis.';
            htmlTextField.height = htmlTextField.textHeight + 4;

            this.addChild( htmlTextField );
        }
    }
}
遮了一弯 2024-12-17 12:34:48

如果您转到此处< /a> 并阅读。
你会看到的。

返回 flash.text:TextFormat — 表示的 TextFormat 对象
指定文本的格式属性。

现在,如果您查看 TextFormat 您会看到默认值几乎都是 0

我很久以前就遇到了这个问题,我发现的唯一解决方法是选择一些文本然后抓取 defaultTextFormat,然后取消选择文本。

我确信还有另一种方法可以做到这一点,但就像我说的,这是我的黑客攻击。

If you go here and read.
you will see.

Returns flash.text:TextFormat — The TextFormat object that represents
the formatting properties for the specified text.

Now if you look at TextFormat You will see the defaults are all pretty much 0

I ran into this issue a long time ago and the only work around I found was to select some text then grab defaultTextFormat and then deselect the text.

I am sure there is another method to do this but like I said it was my hack-a-round.

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