Search Flex Components Free

Custom Search

December 27, 2007

Flex Data Collections List Examples Sample Source Code:

List .mxml


<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="srv.send()" >

<mx:Script>
<![CDATA[

import mx.collections.*;

[Bindable]
public var airportCollection:ArrayCollection;

private function initList() : void
{
airportCollection = new ArrayCollection(srv.lastResult.airports.location);
}

]]>
</mx:Script>

<mx:XML id="source" format="e4x">
<topnode>
<product id="10907"><name>Dreamweaver</name></product>
<product id="20670"> <name>Premiere</name></product>
<product id="30078"><name>Contribute</name></product>
</topnode>
</mx:XML>

<mx:XMLListCollection id="col" source="{source.product}" />

<mx:HTTPService id="srv" url="../assets/airports.xml" result="initList()"/>

<mx:Label text="List bound to an ArrayCollection"/>
<mx:List dataProvider="{airportCollection}" labelField="name" width="200" />

<mx:Label text="List with an XMLCollection as its dataProvider and
labelField=@attribute set" />
<mx:List dataProvider="{col}" labelField="@id" width="200" />

<mx:Label text="List with an XMLCollection as its dataProvider and
labelField=childNode set" />
<mx:List dataProvider="{col}" labelField="name" width="200" />

</mx:Application>

airports.xml
<?xml version="1.0" encoding="utf-8"?>

<airports>
<location>
<abbreviation>IAH</abbreviation>
<name>Houston</name>
</location>
<location>
<abbreviation>BOS</abbreviation>
<name>Boston</name>
</location>
<location>
<abbreviation>MHT</abbreviation>
<name>Houston</name>
</location>
<location>
<abbreviation>JAX</abbreviation>
<name>Jacksonville</name>
</location>
<location>
<abbreviation>CVG</abbreviation>
<name>Cincinatti</name>
</location>
<location>
<abbreviation>ATL</abbreviation>
<name>Atlanta</name>
</location>
<location>
<abbreviation>CDG</abbreviation>
<name>Paris</name>
</location>
<location>
<abbreviation>JFK</abbreviation>
<name>New York</name>
</location>
<location>
<abbreviation>LAX</abbreviation>
<name>Los Angeles</name>
</location>
<location>
<abbreviation>HND</abbreviation>
<name>Tokyo</name>
</location>

</airports>

Related Flex Tutorials