3 Replies Latest reply on Jan 12, 2010 4:40 PM by ehusar

    Selecting Radio Button without Click?

    ehusar Level 1

      I have a radio group like so...

       

      <mx:RadioButtonGroup id="measureFactor" />
      <mx:RadioButton x="143" y="238" label="Kilometers" click="setSpeedKm(event)"  id="km" group="{measureFactor}"/>
      <mx:RadioButton x="257" y="238" label="Miles" click="setSpeedMl(event)" id="ml" selected="true" group="{measureFactor}"/>

       

      I would like to select or switch the radio selection not based on the user's click but on other events.

       

      I was hoping I could do something as simple as this...

       

      measureFactor.ml.selected = true

       

      ...but that doesn't seem to be the right way to do it.  I can't seem to find any example on setting what radio is selected without having them click it.  Can someone point me in the right direction?

       

      Thanks in advance.

        • 1. Re: Selecting Radio Button without Click?
          Gregory Lafrance Level 6

          This code does what you want:

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
            <mx:Script>
              <![CDATA[
                private function clickFunc(evt:MouseEvent):void{
                  if(evt.currentTarget.label=="Select Kilometers"){
                    measureFactor.selectedValue = "Kilometers";
                  }else{
                    measureFactor.selectedValue = "Miles";
                  }
                }
              ]]>
            </mx:Script>
            <mx:Button label="Select Kilometers" click="clickFunc(event)"/>
            <mx:Button label="Select Miles" click="clickFunc(event)"/>
            <mx:RadioButtonGroup id="measureFactor" />
            <mx:RadioButton x="143" y="238" label="Kilometers" id="km" group="{measureFactor}"/>
            <mx:RadioButton x="257" y="238" label="Miles" id="ml" selected="true" group="{measureFactor}"/>    
          </mx:Application>
          

           

          If this post answers your question or helps, please mark it as such.


          Greg Lafrance - Flex 2 and 3 ACE certified

          www.ChikaraDev.com

          Flex / AIR Development, Training, and Support Services

          • 2. Re: Selecting Radio Button without Click?
            ehusar Level 1

            Thanks. Trying to implement this now.  Update in a few minutes....

            • 3. Re: Selecting Radio Button without Click?
              ehusar Level 1

              That works out well. Just needed to update a little bit to handly firering off from a non-click event.

               

              Thanks!