0

在下面的代码中。如果按下按钮“A”,则文本框应填充 A,如果按下按钮“B”,则应填充 B 等等.. 可以这样做吗?如果有人可以指点我灵活的例子会很有帮助。谢谢..

                  s='A';
                for(i=0;i<button.length;i++)
                {
                        txtLogin.text+=s;
                        s++;
                }  

原码..

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

            <mx:Button label="A" click="clickhandler(event)"  x="1" />
            <mx:Button label="B" click="clickhandler(event)"  x="101" />
            <mx:Button label="C" click="clickhandler(event)"  x="201" />
            <mx:Button label="D" click="clickhandler(event)"  x="301" />
            <mx:Button label="E" click="clickhandler(event)"  x="401" />
            <mx:Button label="F" click="clickhandler(event)"  x="501" />
            <mx:Button label="G" click="clickhandler(event)"  x="601" />
            <mx:Button label="H" click="clickhandler(event)"  x="701" />
            <mx:Button label="I" click="clickhandler(event)"  x="801" />
            <mx:Button label="J" click="clickhandler(event)"  x="901" />
            <mx:Button label="K" click="clickhandler(event)"  x="1001" />



            <mx:Script>
                    <![CDATA[
                    import mx.controls.Button;
                    import mx.controls.Alert;

                    public function clickhandler(event:Event):void
                    {

                    var button:Button=event.target as Button;
                    var i:int;
                    var s:String;
                    s='A';
                    for(i=0;i<button.length;i++)
                    {
                            txtLogin.text+=s;
                            s++;
                    }       
            /*      if (button.label=='A')
                    {
                            txtLogin.text+="A";
                            //mx.controls.Alert.show("Button1");
                    }
                    if (button.label=="B")
                    {               
                            txtLogin.text+="B";
                            //mx.controls.Alert.show("Button2");
                    }                       */
                    }
                            ]]>      

            </mx:Script>
                    <mx:TextInput x="231" y="175" id="txtLogin"/>



            </mx:Application>
4

1 回答 1

0

要将单击按钮的字符添加到txtLogin,请将您的更改clickhandler为:

public function clickhandler(event:Event):void
{
    var button:Button=event.target as Button;
    txtLogin.text += button.label;
}

如果要替换的内容txtLogin,请使用

txtLogin.text = button.label    // = instead of +=
于 2010-10-31T12:09:03.627 回答