5 Replies Latest reply on May 5, 2010 8:10 AM by David_F57

    How to set a radio button to be selected?

    kmdguy Level 1

      I'm trying to find out how to do something that should be seemingly simple. That is to create a little function that selects a random radio button as selected. I have 3 radio buttons in a group (see code):

       

      </mx:ApplicationControlBar>

      <mx:RadioButtonGroup id="radiogroupZ"/>

      <mx:RadioButton x="10" y="608" label="Button 1" groupName="radiogroupZ"/>

      <mx:RadioButton x="10" y="634" label="Button 2" groupName="radiogroupZ"/>

      <mx:RadioButton x="10" y="660" label="Button 3" groupName="radiogroupZ"/>

       

      I've tried all kinds of code to try to set Button 1, 2 or 3 as selected but the compiler keeps giving me errors.

       

      Can someone give me an example of a simple function that will set one of these as highlighted? All I need is the code that basically says for example: "Select Button 1 in the group "radiogroupZ to be selected".

       

      Thanks

        • 1. Re: How to set a radio button to be selected?
          SpaghettiCoder Level 3

          // This will have the first button selected.

           

          <mx:RadioButtonGroupd id="radiogroupZ" selectedValue="somethingHere1"/>

           

          <mx:RadioButton x="10" y="608" label="Button 1" value="somethingHere1" groupName="radioGroupZ"/>

          <mx:RadioButton x="10" y="608" label="Button 1" value="somethingHere2" groupName="radioGroupZ"/>

          <mx:RadioButton x="10" y="608" label="Button 1" value="somethingHere3" groupName="radioGroupZ"/>

           

           

           

          // To select something in a function

           

          private function functionName():void

          {

               radiogroupZ.selectedValue = "somethingHere1";

          }

          • 2. Re: How to set a radio button to be selected?
            kmdguy Level 1

            Hi there,

             

            Thanks so much. That did the trick. The one odd thing is that the compiler keeps giving me an error when I save which reads:

             

            1120: Access of undefined property radiogroupZ.

             

            The script works fine however but this error persists in the "Problems" tab. I quit Flex, open it back up and the error comes back in there upon the next time I save the application. Again, the script does work but Flex keeps giving me this error message. Any ideas how to get rid of it?

             

            Thanks again!

            • 3. Re: How to set a radio button to be selected?
              SpaghettiCoder Level 3

              If you added value to your radio, and you're calling a value that does exist I'm not sure why it'd throw an error.

               

              Have you tried cleaning your project?

               

              In flex builder click Project

              Then click clean...

              • 4. Re: How to set a radio button to be selected?
                David_F57 Level 5

                hi,

                 

                I'd be checking the case and spelling of the radiogroup name and the call is consistent...its always the dumbest things that catch us out. 

                 

                 

                David.

                • 5. Re: How to set a radio button to be selected?
                  kmdguy Level 1

                  Ya, I just cleaned it and no change. Again, the function works fine. It's called when a particular state is changed. Yet the error message persists.

                   

                  The radiogroup is embedded in a form. I've attached a picture of the form code and the function code with error. It's no big deal I guess if the error never goes away as long as the function works.

                   

                  error1.png

                  error2.png