topical media & game development
professional-flex-code-06-DataProviders.mx
professional-flex-code-06-DataProviders.mx
[swf]
flex
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
public var myArray:Array = ["United States", "South Africa", "United Kingdom"];
[Bindable]
public var myCollection:ArrayCollection = new ArrayCollection(["United States", "South Africa", "United Kingdom"]);
public function addCountryToArray(country:String):void
{
myArray.push(country);
}
public function addCountryToCollection(country:String):void
{
myCollection.addItem(country);
}
]]>
</mx:Script>
<mx:TextInput id="countryTextInput" text="Argentina" />
<mx:Label text="Bound to Array" />
<mx:Button click="addCountryToArray(countryTextInput.text)" label="Add Country to Array" />
<mx:List dataProvider="{myArray}" width="200" />
<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>
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.