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. Here is a work around if you wish to enable editing only on double-click:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="init();">
<mx:Script>
<![CDATA[
import mx.events.ListEvent;
import mx.core.EventPriority;
private function init():void {
myList.addEventListener(ListEvent.ITEM_DOUBLE_CLICK, onItemDoubleClick,
false, EventPriority.DEFAULT_HANDLER);
myList.addEventListener(ListEvent.ITEM_EDIT_END, onItemEditEnd,
false, EventPriority.DEFAULT_HANDLER);
}
private function onItemDoubleClick(event:ListEvent):void {
if (event.itemRenderer.data == "One") {
return;
}
if (event.isDefaultPrevented()) {
return;
}
myList.editable = true;
myList.editedItemPosition = {columnIndex:0, rowIndex:event.rowIndex};
}
private function onItemEditEnd(event:ListEvent):void {
myList.editable = false;
}
]]>
</mx:Script>
<mx:ArrayCollection id="myData">
<mx:String>One</mx:String>
<mx:String>Two</mx:String>
<mx:String>Three</mx:String>
<mx:String>Four</mx:String>
</mx:ArrayCollection>
<mx:Label text="Doubleclick any item to edit…"/>
<mx:List id="myList" doubleClickEnabled="true" dataProvider="{myData}" width="200"/>
</mx:Application>
Click here for live example.
Let me know incase of any bugs…




thanks tons !
By: kamel on November 30, 2008
at 4:26 pm
Awesome posting … your recipe worked perfectly. Thank you!!
By: Neil Kolban on May 21, 2009
at 5:25 am
Thank you! This is, what I have searched for… but there is something, what I do not understand:
After “EditEnd” the key control with up and down arrow to navigate in the list is lost. You have to click once more an item to use it again.
Could you help me to get this “navigate-with-key-feature” back without to click once more an item???
Best regards,
Isabel
By: Isabel on July 15, 2009
at 11:47 am
Thank you kindly! This works GREAT.
By: Kojo on August 28, 2009
at 3:43 am
Works fine thanks!
@Isabel:
private function onItemEditEnd(event:ListEvent):void {
myList = false;
myList.setFocus() ;
}
Not perfect but do the trick
By: bLb on November 5, 2009
at 7:05 am