Flex Spark RadioButton Deselected Event? -
is there way listen this? can listen click selects radiobutton, can't seem find way listen when radiobutton has been deselected.
any ideas?
thanks!
back in flex 2 days, "change" event triggered when radio button deselected. however, little convenience disappeared in flex 3, reason, , don't believe provided sort of replacement event.
handling events @ radiobuttongroup level fine , well, except there times when want handle events on radio button level -- particularly if hoping interact data provider entry via itemrenderer drawing radio button.
conveniently, have little bit of boilerplate code can use drop-in replacements radiobutton , radiobuttongroup provide "unselect" event @ radio button level. here smartradiobutton, first of all:
<?xml version="1.0" encoding="utf-8"?> <s:radiobutton xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx"> <fx:script> <![cdata[ import events.smartradiobuttonevent; public function notifydeselect():void { dispatchevent(new smartradiobuttonevent('deselect')); } ]]> </fx:script> <fx:metadata> [event(name="deselect", type="events.smartradiobuttonevent")] </fx:metadata> </s:radiobutton>
and here smartradiobuttongroup:
<?xml version="1.0" encoding="utf-8"?> <s:radiobuttongroup xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" change="selectionchanged();" > <fx:script> <![cdata[ import spark.components.radiobutton; import components.smartradiobutton; protected var oldselection:smartradiobutton = null; // notify our old selection has been deselected, , update // reference new selection. public function selectionchanged():void { var newselection:smartradiobutton = this.selection smartradiobutton; if (oldselection == newselection) return; if (oldselection != null) { oldselection.notifydeselect(); } oldselection = newselection; } // override properties make sure update oldselection correctly, // in event of programmatic selection change. override public function set selectedvalue(value:object):void { super.selectedvalue = value; oldselection = super.selection smartradiobutton; } override public function set selection(value:radiobutton):void { super.selection = value; oldselection = super.selection smartradiobutton; } ]]> </fx:script> </s:radiobuttongroup>
the 2 property overrides in there make sure correctly update oldselection, in event of programmatic change group's selection.
smartradiobuttonevent isn't fancy or important. plain event, since there isn't special payload.
i have tested above code, , works, there surely edge conditions, , other oddities should addressed, if it's used in larger system.
Comments
Post a Comment