TextField单词被剪切为AS3

时间:2012-07-27 17:19:41

标签: actionscript-3 flash textfield cut words

我遇到TextField组件在每行末尾切换单词的问题,即使wordWrap属性设置为true。

示例:

This is a test te
xt, this is a tes
t text. This is a
test text.

如何解决这个问题?感谢

编辑1:

我有一个使用参数.size = 20的textFormat。

编辑2:

以下是相关代码:

var tx:TextField = new TextField();
var tf:TextFormat = new TextFormat();

tf.size = 18;

tx.defaultTextFormat = tf;      
tx.autoSize = TextFieldAutoSize.CENTER;
tx.multiline = true;
tx.wordWrap = true;
tx.width = 835;

tx.text = "Long text..";

2 个答案:

答案 0 :(得分:1)

你可以用合适的保证金来解决这个问题。 你需要多少margon取决于字体大小。 你必须测试一下。

只需将x px宽度添加到textField

即可

tf.width + = 10;

并向tf添加相同金额的右边距:

tf.rightMargin = 10;

现在没有任何词语被删除

答案 1 :(得分:0)

此应用适用于我。它和你的一样,除了我在应用程序中没有指定缩放,并且左上角的对齐方式。如果我不这样做,文字就不能正确呈现。

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

    public class Woot extends Sprite
    {
        public function Woot()
        {
            super();
            stage.align=StageAlign.TOP_LEFT;
            stage.scaleMode=StageScaleMode.NO_SCALE;
            var tx:TextField = new TextField();
            var tf:TextFormat = new TextFormat();
            tf.size = 18;
            tx.defaultTextFormat = tf;
            tx.autoSize = TextFieldAutoSize.CENTER;
            tx.multiline = true;
            tx.wordWrap = true;
            tx.width = 835;
            tx.text = "this is some long text. this is some long text. this is some long text.this is some long text. this is some long text. this is some long text.this is some long text. this is some long text. this is some long text.this is some long text. this is some long text. this is some long text.this is some long text. this is some long text. this is some long text.this is some long text. this is some long text. this is some long text.this is some long text. this is some long text. this is some long text.this is some long text. this is some long text. this is some long text.this is some long text. this is some long text. this is some long text.this is some long text. this is some long text. this is some long text.this is some long text. this is some long text. this is some long text.this is some long text. this is some long text. this is some long text.this is some long text. this is some long text. this is some long text.";
            addChild(tx);
        }
    }
}