【问题标题】:Adding a text field with the click of a button using MXML or actionscript使用 MXML 或 actionscript 单击按钮添加文本字段
【发布时间】:2014-03-15 17:23:41
【问题描述】:

我想添加一个按钮,单击该按钮会添加另一个文本字段。我正在使用 adobe flash builder 编写应用程序,因此它需要使用 MXML 或 actionscript。关于如何做到这一点的任何想法?

事件处理程序按钮当前指向此代码,但是在第一次添加文本框后,它停止并且不再添加。如何在每次单击按钮时循环添加文本字段?

<fx:Script>

    <![CDATA[
        protected function tableID(event:MouseEvent):void
        {               
            var name:TextInput = new TextInput;
            addElement(name);
            name.move(50, 200);
        }
    ]]>
</fx:Script>

MXML:

<s:Button id="addBtn" x="175" y="450" label="+" click="tableID(event)" />

【问题讨论】:

  • 你怎么知道 textinput 只在第一次点击时被添加,而不是在任何后续点击中?查看您的代码,我的假设是每次您单击按钮时,都会添加文本框,但是,它会添加到先前的文本输入之上,因此您无法直观地看到它。您还可以为按钮节点发布您的 MXML,与事件挂钩。

标签: apache-flex actionscript flash-builder mxml


【解决方案1】:

只需为文本字段使用布尔变量。将变量设置为 includeInLayout 和对文本字段可见。单击按钮时,将布尔变量的条件设置为真或假。我想这会对你有所帮助。

【讨论】:

    【解决方案2】:

    你可以试试这个方法:

    <fx:Script>
        <![CDATA[
            import mx.controls.TextInput;
            protected function bt_clickHandler(event:MouseEvent):void
            {
                // TODO Auto-generated method stub
                var item:TextInput = new TextInput();
                item.width = 50;
                _parent.addElement(item);
            }
        ]]>
    </fx:Script>
    
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <mx:Tile id="_parent" width="100%" height="100%">
        <s:Button id="bt" label="+" click="bt_clickHandler(event)"/>
    </mx:Tile>
    

    【讨论】:

      猜你喜欢
      • 2015-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多