Replace item in a List
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
import mx.events.CollectionEventKind;
import mx.events.CollectionEvent;
import mx.collections.SortField;
import mx.collections.Sort;
import mx.collections.ArrayCollection;
private var index:Number = 0;
public function addItem():void
{
myCollection.addItem({label: myTextInput.text, data: index});
index++;
}
private function updateItem():void
{
if (myList.selectedItem != null)
myCollection.setItemAt({label: myTextInput.text, data: index}, myList.selectedIndex);
}
</mx:Script>
<mx:ArrayCollection id="myCollection"/>
<mx:TextInput id="myTextInput" />
<mx:List id="myList" dataProvider="{myCollection}" width="200" height="200" />
<mx:Button label="ADD" click="addItem()" />
<mx:Button label="UPDATE" click="updateItem()" />
<mx:TextArea id="myTextArea" width="200" height="200" />
</mx:Application>
Related examples in the same category