Mega Code Archive

 
Categories / Flex / Data Model
 

Bind ArrayCollection to List and update ArrayCollection to change List

<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">     <mx:Script>                      import mx.collections.ArrayCollection;                                       [Bindable]             public var myCollection:ArrayCollection = new ArrayCollection(["A", "B", "C"]);                          public function addCountryToCollection(country:String):void             {                 myCollection.addItem(country);             }                         </mx:Script>          <mx:TextInput id="countryTextInput" text="D" />     <mx:Label text="Bound to Collection" />     <mx:Button click="addCountryToCollection(countryTextInput.text)" label="Add Country to Collection" />     <mx:List dataProvider="{myCollection}" width="200" />      </mx:Application>