flexcoders  

[flexcoders] RadioButton change event not firing in Flex 3 when button in group is deselected

Samuel Neff
Wed, 25 Jun 2008 13:11:19 -0700

In Flex 3 when you have radio buttons in a group and click on one of the
radio buttons, only the change event for the clicked-on radio button fires.
The radio button that was previously selected does not dispatch a change
event (it did in Flex 2).

This behavior can be overridden by the Flex 2 compatibility flag, but it's
not mentioned in the compatibility document as far as I can tell

http://learn.adobe.com/wiki/display/Flex/Backwards+Compatibility+Issues

For example, run the following code with Flex 2 SDK:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; layout="vertical">
    <mx:RadioButton id="b1" label="1" change="trace('1 changed:' +
b1.selected);" />
    <mx:RadioButton id="b2" label="2" change="trace('2 changed:' +
b2.selected);" />
    <mx:RadioButton id="b3" label="3" change="trace('3 changed:' +
b3.selected);" />
</mx:Application>

click on one gives..

1 changed:true

then clicking on 2 gives...

2 changed:true
1 changed:false

and clicking on 3 gives...

3 changed:true
2 changed:false


however, if you then run the same code with Flex 3 SDK, you get:


click on one gives..

1 changed:true

then clicking on 2 gives...

2 changed:true

and clicking on 3 gives...

3 changed:true

so in Flex 3 you never get the change events when the old radio buttons are
set to selected=false.

Here's the changed code that I think causes the problem.


            if (FlexVersion.compatibilityVersion < FlexVersion.VERSION_3_0)
            {
                 if (toggle)
                    dispatchEvent(new Event(Event.CHANGE));
            }
            else
            {
                if (toggle && !isProgrammatic)
                    dispatchEvent(new Event(Event.CHANGE));
            }


is this really correct behavior?  Why wouldn't you want the change event to
fire when the value changed?  There's an isProgrammatic check in there, but
this is not really a programmatic change, it's in response to a user
clicking on a different radio button in the group.

Thanks,

Sam


-----------------------------------------------------------------
We're Hiring! Seeking passionate Flex, C#, or C++ (RTSP, H264) developer in
the Washington D.C. Contact [EMAIL PROTECTED]