Consider the following radio button example.
<?xml version='1.0' encoding='utf-8'?> <mx:Application xmlns:mx='http://www.adobe.com/2006/mxml'> <mx:Script> <![CDATA[ private function getRb1():RadioButton { trace(rb1 == null); return rb1; } ]]> </mx:Script> <mx:VBox> <mx:RadioButtonGroup **id='rbg' selection='{getRb1()}**'/> <mx:RadioButton id='rb1' label='Radio Button 1' /> <mx:RadioButton id='rb2' label='Radio Button 2' /> <mx:RadioButton id='rb3' label='Radio Button 3' /> </mx:VBox> </mx:Application>
The problem is that I can not refer to rb1 while defining RadioButtonGroup, rb1 is null at that time, but i can use the selectedValue to set the initial selction.
I was just wondering is this some special case or its not safe to refer to components in mxml in general.
Thanks,
I’m not quite sure what you’re asking, but hopefully this’ll answer your question — from the Flex docs:
In general, though, making component references in MXML is totally fine; that’s how effects are often handled, among many other things. For example:
However in your case, assuming you’re having trouble setting the selected item, it might be because you haven’t specified the
groupattribute on the radio buttons; omitting that detaches the group component from the individual buttons. Once you add that, you can bind the group’s selection property using aBindablevariable containing a reference to a component, like so:Does this make sense? Hopefully it’s not completely off the mark; post back and let me know and I’ll try to help out as best I can.