我曾经知道如何做到这一点,所以,我知道这是可能的,但我无法再弄清楚了。我正在通过设置width属性来改变我的TextField的宽度,但这会使文本变形。我想改变文本字段的宽度而不改变字体的外观(显然)。我相信它与autoText或者一些这样的白痴有关(为什么我会想要扭曲我的文字?!)但是我不记得了。
myField.width = 100; //如果原始宽度为50,则只需将字段拉伸到100,而不是添加50个可以绘制字符的像素。
TIA
答案 0 :(得分:2)
在IDE中,您需要
a)双击文本字段。这将带您进入文本字段的编辑模式。然后调整大小。
或
b)选择文本工具,然后调整其大小。
使用变换工具调整大小会增加宽度,就好像它是一个形状一样(在某些动画中它是有用的,所以它真的不那么愚蠢)
答案 1 :(得分:1)
**编辑**
这是一个如何调整TextField大小的代码示例:
http://wonderfl.net/c/qbDv
但这仅适用于动态 TextFields。使用代码创建的TF是DYNAMIC或INPUT,但在IDE中,您可以创建STATIC的TF,并且不能通过ActionScript调整其大小。因此,您必须更改TextField的类型或通过脚本创建TF。
答案 2 :(得分:1)
我猜你的问题是TextField.defaultTextFormat。
只需设置一个TextFormat对象,然后在文本字段中设置默认的文本格式,无论你做什么,它都应该保留文本格式。
您会看到当您更改文本字段的任何内容时,文本格式会重置,您必须重新应用它。但是,如果您设置默认文本格式,它将自动处理。
这是一个肮脏的小原型。
package src
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFormat;
public class Main extends Sprite
{
private var tx:TextField;
private var txf:TextFormat;
public function Main()
{
addEventListener(Event.ADDED_TO_STAGE, initMain);
}
private function initMain(e:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, initMain);
// setup a text format so you can keep your text the same all the time.
txf = new TextFormat('Arial', 12, 0x000000);
tx = new TextField();
tx.width = 50;
tx.text = "I want this text not to wrap so it will be resized at runtime."
// Turned this on for testing purposes only.
tx.wordWrap = true;
tx.defaultTextFormat = txf; // This line is the x factor most likely.
tx.x = 100;
tx.y = 100;
addChild(tx);
stage.addEventListener(MouseEvent.CLICK, toggleTextFieldSize, false, 0 ,true);
}
private function toggleTextFieldSize(e:MouseEvent):void
{
if (tx.width == 50)
{
tx.width = 400;
}
else
{
tx.width = 50;
}
}
}
}
希望这就是你要找的东西。
答案 3 :(得分:0)
另一种解决方案是使用文本字段的包装器,如Group
元素,只需增加其宽度。
答案 4 :(得分:-1)
您还可以使用文本格式并分配左右边距
myTextFormat.leftMargin = some number
和
myTextFormat.rightMargin = same number
作为左边距。