addEventListener(“click”, mx.utils.Delegate.create(this, clickRadioButton);

 


From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of [EMAIL PROTECTED]
Sent: Tuesday, August 16, 2005 12:23 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Cannot assign selected value from a radiobutton that was created dynamically.

 



I am creating radioButtons dynamically using an array. When I try to
assign the selected value into a Text or TextArea it doesn't work. It seems
that I am using addEventListener correctly since I am able to see the
event.target.data in an Alert.

  This application shows what I mean:

1. The radiobuttons are created out of an array.
2. When you click on any of them you get an Alert showing the data you
have clicked. However, it doesn't change the text of the TextArea.
Eventually I want to assign this value, to some place else.
3. If you execute the same code  txtReceipt.text="Button" - by clicking on
the Button it does change the text.

the code below is runnable and shows the problem ...

Thanks ....

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" >
    <mx:Script>
    <![CDATA[

        public var arrayList:Array= new Array();


       private function getmyList(): Void
       {
        arrayList[0]="item1";
        arrayList[1]="item2";
        arrayList[2]="item3";
             addElement();
        }

        // Add radiobuttons dynamically
public function addElement() {
        var totalOptions:Number = arrayList.length;
            var isSelected:Boolean;
            //mx.controls.Alert.show(String(totalOptions),"Total Options");
       for(var i:Number=0;i<totalOptions;i++) {
                 if (i==0)  // Selects the first Radio Button
                        isSelected=true
                   else
                         isSelected=false
            receiptHBox.createChild(mx.controls.RadioButton, undefined,
{label:"item"+i , data:"item"+i ,groupName:"group1" ,selected:isSelected}
).addEventListener("click",clickRadioButton);

        }
    }
      public function clickRadioButton(event)
      {
            txtReceipt.text=event.target.data; // This doesn't work
            mx.controls.Alert.show(event.target.data,"Test"); // But the
the data is there .....

      }
      public function changeText()
      {
            txtReceipt.text="Button";
      }


    ]]>
    </mx:Script>



   <mx:TextArea id="txtReceipt"  />
      <mx:HBox id="receiptHBox"  initialize="getmyList()">
            <!--  Radio buttons are created dynamically -->
      </mx:HBox>

   <mx:Button label="Button" click="changeText()"/>


  </mx:Application>



---------------------------------------------------------------------------
This e-mail message (including attachments, if any) is intended for the use
of the individual or entity to which it is addressed and may contain
information that is privileged, proprietary , confidential and exempt from
disclosure.  If you are not the intended recipient, you are notified that
any dissemination, distribution or copying of this communication is
strictly prohibited.  If you have received this communication in error,
please notify the sender and erase this e-mail message immediately.
---------------------------------------------------------------------------







--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




YAHOO! GROUPS LINKS




Reply via email to