Disabling rollout behavior of a selected item in a Flex 4 List
Posted by Ian Serlin | Tweet This | Filed under Actionscript 3, Adobe Flex, problem solution
Problem
You want a selected item in a Flex 4 List control to keep its highlighting even when a mouse rollout event occurs. By default Flex 4 Lists will execute the rollout behavior even on a selected item which can have unexpected consequences such as deselecting an item.
Solution
There’s no built-in option at the time of this writing to disable this behavior, so here is an extended Flex 4 item renderer to block this default behavior if the current item renderer catching the rollout event is in its ’selected’ state.
NonDeselectingItemRenderer.as
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | package components.supportClasses { import flash.events.MouseEvent; import spark.components.supportClasses.ItemRenderer; public class NonDeselectingItemRenderer extends ItemRenderer { public function NonDeselectingItemRenderer() { super(); } override protected function itemRenderer_rollOutHandler(event:MouseEvent):void { if( super.currentState != "selected" ){ super.itemRenderer_rollOutHandler( event ); } } } } |