【问题标题】:Stacking Dynamic Text Fields Flash/ActionScript 3堆叠动态文本字段 Flash/ActionScript 3
【发布时间】:2013-03-03 00:33:20
【问题描述】:

我正在通过基于 XML 文件的循环添加一系列文本字段。字段的宽度始终为200 px,因此根据 XML 节点中包含的文本量,文本字段的高度会有所不同。我需要一种方法将这些字段堆叠在一起,根据它们的高度加上每个字段之间的10 px 空间。以下是我创建文本字段的方式。

for(var i:int; i < xml.item.length(); i++)
{
    var theText:TextField = new TextField();
    addChild(theText);
    theText.wordWrap = true;
    theText.width = 200;
    theText.antiAliasType = AntiAliasType.ADVANCED;
    theText.autoSize = TextFieldAutoSize.LEFT;
    theText.selectable = false;
    theText.htmlText = xml.item[i].@theText;
};

【问题讨论】:

    标签: actionscript-3 flash actionscript textfield


    【解决方案1】:

    您可以使用文本字段的高度来跟踪高度。

    var startHeight:int = 0;
    for(var i:int; i < xml.item.length(); i++)
    {
        var theText:TextField = new TextField();
        addChild(theText);
    
        theText.y = startHeight;
    
        theText.wordWrap = true;
        theText.width = 200;
        theText.antiAliasType = AntiAliasType.ADVANCED;
        theText.autoSize = TextFieldAutoSize.LEFT;
        theText.selectable = false;
        theText.htmlText = xml.item[i].@theText;
    
        startHeight += theText.height + 10;
    }
    

    【讨论】:

    • 谢谢!我知道这很简单。对于遇到此问题的其他人来说只有一个小改动,第一行应该是:“var startHeight:int = 0;”
    • 哈哈是的,编辑过多的 C++/AS3 混合有时会这样 :)
    猜你喜欢
    • 1970-01-01
    • 2012-07-15
    • 1970-01-01
    • 2012-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多