gpt4 book ai didi

flash - AS3 中的 TextFieldAutoSize 和 textWidth

转载 作者:行者123 更新时间:2023-12-04 21:50:53 25 4
gpt4 key购买 nike

这个问题不太可能对任何 future 的访客有帮助;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于互联网的全局受众。如需帮助使这个问题更广泛适用,visit the help center .




10年前关闭。




我正在尝试为 AS3 中的文本字段绘制背景。

我有一个带有嵌入字体并使用 autoSize = TextFieldAutoSize.LEFT 的 TextField。我将文本分配给 TextField,然后调用 try 使用 TextField 的 textWidth 绘制一个 roundedRect。文本字段宽度始终小于实际文本宽度。

还有另一种方法可以获得实际的文本宽度吗?我做了一些快速的谷歌搜索,但我没有找到任何东西。

代码:

var tfProgramName:TextField = TextUtil.createTextField(true,"Arial",20,true);
tfProgramName.width = 100;
tfProgramName.autoSize = TextFieldAutoSize.LEFT;
tfProgramName.x = 5;
tfProgramName.y = 5;
addChild(tfProgramName);

tfProgramName.text = _program.title;
background.graphics.clear();
background.graphics.beginFill(0xFF0000,0.75);
background.graphics.drawRoundRect(0,0,tfProgramName.textWidth+10,this.height+10,5,5);
background.graphics.endFill();

在我的例子中 textWidth 类似于 373,但它应该更接近 400。它绝对接近,但它似乎没有考虑字体或字体大小。

最佳答案

我不能保证它会更好,但看看 TextLineMetrics它为您提供的信息比其他任何东西都多,因此这可能是您最好的选择。

关于flash - AS3 中的 TextFieldAutoSize 和 textWidth,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4963948/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com