5 Replies Latest reply on Sep 3, 2007 10:48 PM by ThinkingProspects

    RadioGroup estrategy

    paulo.larini
      Hi, I´m creating a couple of radio grups in action script, and setting a default radiobutton value.

      if I get the radioGroupX..selectedValue, it comes null.

      if I do the same comand, inside a button.click event I get the value.

      It seems that the radioGroup is not full created yet.

      How can I make it full created?
        • 1. Re: RadioGroup estrategy
          paulo.larini Level 1
          Here is an example:

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

          <mx:Script>
          <![CDATA[
          import mx.controls.RadioButton;
          import mx.controls.RadioButtonGroup;
          public function exec():void {
          var rg:RadioButtonGroup = new RadioButtonGroup();
          var b1:RadioButton = new RadioButton()
          var b2:RadioButton = new RadioButton()
          var b3:RadioButton = new RadioButton()
          b1.label="b1";
          b2.label="b2";
          b3.label="b3";
          b1.group=rg;
          b2.group=rg;
          b3.group=rg;

          rg.selectedValue="b2";

          if (rg.selectedValue==null)
          rg.selectedValue="b3";

          hbox.addChild(b1);
          hbox.addChild(b2);
          hbox.addChild(b3);

          }
          ]]>
          </mx:Script>
          <mx:HBox id="hbox"/>
          <mx:Button label="xxxxx" click="exec()"/>
          </mx:Application>
          • 2. Re: RadioGroup estrategy
            mae@ccg
            Seems to me you should do the addChild calls first, then try to manipulate the properties...

            I didn't try this myself.
            • 3. Re: RadioGroup estrategy
              mae@ccg Level 1
              What event were you trying this in? Your code worked for me in the creationComplete event of the hbox.
              • 4. Re: RadioGroup estrategy
                paulo.larini Level 1
                Hey mae, this is the exact case. I just can´t figure out what´s happening.
                • 5. Re: RadioGroup estrategy
                  ThinkingProspects
                  I tried with empty string and seems working:

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

                  <mx:Script>
                  <![CDATA[
                  import mx.controls.RadioButton;
                  import mx.controls.RadioButtonGroup;
                  public function exec():void {
                  var rg:RadioButtonGroup = new RadioButtonGroup();
                  var b1:RadioButton = new RadioButton()
                  var b2:RadioButton = new RadioButton()
                  var b3:RadioButton = new RadioButton()
                  b1.label="b1";
                  b2.label="b2";
                  b3.label="b3";
                  b1.group=rg;
                  b2.group=rg;
                  b3.group=rg;



                  rg.selectedValue="b2";

                  if (rg.selectedValue=="")
                  rg.selectedValue="b3";
                  hbox.addChild(b3);
                  hbox.addChild(b2);
                  hbox.addChild(b1);

                  }
                  ]]>
                  </mx:Script>
                  <mx:HBox id="hbox"/>
                  <mx:Button label="xxxxx" click="exec()"/>
                  </mx:Application>