2 Replies Latest reply on Nov 2, 2010 6:23 AM by manjeet.patel

    Dynamic radio button and group

    manjeet.patel Level 1


      Hi, we have create dynamic radio button and group on “application creation complete” event , but which I am try to get number of radio button its show zero, see below code




      import flash.utils.setTimeout;
      import mx.controls.Alert;
      import mx.events.FlexEvent;
      import spark.components.RadioButton;
      import spark.components.RadioButtonGroup;
      private var  rbg:RadioButtonGroup;
      private var  rb1:RadioButton;
      private var  rb2:RadioButton;
      private var dcount:int = 0;
      protected function application1_creationCompleteHandler(event:FlexEvent):void
           // TODO Auto-generated method stub
           // TODO Auto-generated method stub
           rb1 = new RadioButton();
           rb2 = new RadioButton();
           rbg = new RadioButtonGroup();
           rb1.label = "Radio1";
           rb2.label = "Radio2";
           rb1.group = rbg;
           rb2.group = rbg;
           checkRadioButton ();  
      protected function checkRadioButton ():void
           Alert.show("In checkRadioButton function : " +  rb1.group.numRadioButtons.toString()); 



      If I put some Time interval to call  checkRadioButton function its working fine,


      //checkRadioButton ();  



      but this is not best practice.
      why this happen ….can anybody  clear  this or any other way to do this.


      Thanks in advance