2015-10-31 78 views
0

我正在嘗試使用按鈕進行文本輸入,但到目前爲止,我只能輸入一個數字。 (如果我點擊另一個按鈕進行第二次輸入,它會清除第一個輸入。)有沒有辦法解決這個問題?Flex:使用按鈕輸入數字

我在這裏添加了我的代碼和一張圖片來展示我正在嘗試做什麼。

我真的很感謝你的幫忙!

<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
<?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>