Archive

Archive for January, 2009

Double click editable List component

January 26th, 2009 1 comment

This code is a simple extention of the Flex List component to make a line item editable on double click, not single click which is the default behaviour.

 

Actionscript:
  1. package{
  2.     import mx.controls.List;   
  3.     import flash.events.MouseEvent;
  4.     import mx.events.ListEvent;
  5.  
  6.     public class DoubleClickList extends List{
  7.         public function DoubleClickList(){
  8.             super();
  9.             doubleClickEnabled = true;
  10.             addEventListener(MouseEvent.DOUBLE_CLICK, handleDoubleClick);
  11.             addEventListener(ListEvent.ITEM_EDIT_END, handleItemEditEnd);
  12.         }
  13.        
  14.        
  15.         protected function handleDoubleClick(p_evt:MouseEvent):void{
  16.             var isEventPrevented:Boolean = p_evt.isDefaultPrevented();
  17.             if(!p_evt.isDefaultPrevented()){
  18.                 editable = true;
  19.                 editedItemPosition = {columnIndex:0, rowIndex:selectedIndex};         
  20.             }
  21.         }
  22.         protected function handleItemEditEnd(p_evt:ListEvent):void{
  23.             editable = false;
  24.         }      
  25.     }
  26. }

Categories: Flash development Tags: