Flex:使用按钮输入数字

时间:2015-10-31 00:26:28

标签: flex button text textinput

我试图使用按钮进行文字输入,但到目前为止我只能输入一个数字。 (如果我单击另一个按钮进行第二次输入,则会删除第一个输入。)有没有办法解决这个问题?

我在这里添加了我的代码和图片,以显示我想要制作的内容。

我非常感谢你的帮助!

    

<mx:Button x="18" y="116" label="1" width="20" height="20" fontSize="7" click="one(event)"/>
<mx:Button x="37" y="116" label="2" width="20" height="20" fontSize="7" click="two(event)"/>
<mx:Button x="56" y="116" label="3" width="20" height="20" fontSize="7" click="three(event)"/>
<mx:Button x="18" y="135" label="4" width="20" height="20" fontSize="7" click="four(event)"/>
<mx:Button x="37" y="135" label="5" width="20" height="20" fontSize="7" click="five(event)"/>
<mx:Button x="56" y="135" label="6" width="20" height="20" fontSize="7" click="six(event)"/>
<mx:Button x="18" y="154" label="7" width="20" height="20" fontSize="7" click="seven(event)"/>
<mx:Button x="37" y="154" label="8" width="20" height="20" fontSize="7" click="eight(event)"/>
<mx:Button x="56" y="154" label="9" width="20" height="20" fontSize="7" click="nine(event)"/>
<mx:Button x="18" y="173" label="x" width="20" height="20" fontSize="7" click="erase(event)"/>
<mx:Button x="37" y="173" label="0" width="20" height="20" fontSize="7" click="zero(event)"/>
<mx:Button x="56" y="173" width="20" height="20" label="ent" fontSize="7" click="ent(event)"/>

public function one(event:MouseEvent):void {
        numberCopies.text = "1";
    }
    public function two(event:MouseEvent):void {
        numberCopies.text = "2";
    }

...

image

1 个答案:

答案 0 :(得分:1)

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" >

    <fx:Script>
        <![CDATA[

            [Bindable] public var copies:String = "";

            public function one(event:MouseEvent):void {
                copies += "1";
            }
            public function two(event:MouseEvent):void {
                copies += "2";
            }

        ]]>
    </fx:Script>
    <s:Label id="numberCopies" text="{copies}"/>
    <mx:Button x="18" y="116" label="1" width="20" height="20" fontSize="7" click="one(event)"/>
    <mx:Button x="37" y="116" label="2" width="20" height="20" fontSize="7" click="two(event)"/>


</s:Application>