Avg. Rating 2.7

Problem

When for a list control the property editable is set to true, one can click on the item and rename the label or edit the item if an item editor is set. But, I want to have a single-click select and double-click edit policy which is mostly default in other applications.

Solution

This problem is solved with a little hack using Timer class and itemEditBeginning event of List Control.

Detailed explanation

Using the preventDefault method of ListEvent Class we can prevent the List item from being edited.

Now here, this method is called when the time between successive clicks is more than a predefined time (400 msec in example).
So when a user clicks on an item in List, the item is prevented from being edited, then if the user clicks again on the item within 400 msec, preventDefault method is not called and the item is allowed to be edited.
The relevant code;

-Creating a timer Object;
import flash.utils.Timer;
private var timer:Timer = new Timer(400,1); //time between clicks, set to 400 ms
-Creating a List Control with properties:
<mx:List editable="true" itemEditBeginning="startEdit(event)" dataProvider="{listItemArray}"/>

-Defining the function startEdit

private function startEdit(evt:ListEvent):void
{
if(!timer.running){
timer.start(); // if timer is not running then start it
evt.preventDefault(); // stop editing
trace("stopped editing");
}else{
//if timer is running ie time between click is less than 400 msec
trace("allowed editing");
}
}
list_edit.zip
[Example with View Source Enabled]
Report abuse

Related recipes