Add, Remove, or Retrieve Data from an ArrayList
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:s="library://ns.adobe.com/flex/spark">
<mx:ArrayList id="list">
<mx:String>A</mx:String>
<mx:String>B</mx:String>
<mx:String>C</mx:String>
</mx:ArrayList>
<mx:Script>
private function addItem():void
{
list.addItemAt( "Martin Foo", 2 );
}
private function removeItem():void
{
list.removeItemAt( 2 );
list.removeItem( list.getItemAt( 2 ) );
}
private function getItemIndex():void
{
trace( "index: " + list.getItemIndex( "Josh Noble" ) );
}
</mx:Script>
<s:DropDownList dataProvider="{list}" />
<mx:Button label="add" click="addItem();" />
<mx:Button label="remove" click="removeItem();" />
<mx:Button label="get" click="getItemIndex();" />
</mx:Application>
Related examples in the same category