The following example shows how you can set the label field on the Flex Gumbo FxList control by setting the labelField property.
Support for the labelField and labelFunction properties on the FxList control was added in trunk build 5181. To download newer builds of the Flex Gumbo SDK, visit the “Gumbo Downloads” page on opensource.adobe.com
Full code after the jump.
To use the following code, you must have Flash Player 10 and a Flex Gumbo SDK installed in your Flex Builder 3. For more information on downloading and installing the Gumbo SDK into Flex Builder 3, see “Using the beta Gumbo SDK in Flex Builder 3″.
<?xml version="1.0"?>
<!-- http://blog.flexexamples.com/2009/03/08/setting-a-label-field-on-a-fxlist-control-in-flex-gumbo/ -->
<FxApplication name="FxList_labelField_test"
xmlns="http://ns.adobe.com/mxml/2009"
backgroundColor="white">
<layout>
<BasicLayout />
</layout>
<FxList id="list"
labelField="name"
horizontalCenter="0"
verticalCenter="0">
<dataProvider>
<ArrayCollection>
<Object name="The" price="0.23" />
<Object name="quick" price="1.03" />
<Object name="brown" price="0.98" />
<Object name="fox" price="1.19" />
<Object name="jumps" price="0.28" />
<Object name="over" price="0.42" />
<Object name="the" price="0.09" />
<Object name="lazy" price="0.81" />
<Object name="dog" price="0.72" />
</ArrayCollection>
</dataProvider>
</FxList>
</FxApplication>
Due to popular demand, here is the “same” example in a more ActionScript friendly format:
<?xml version="1.0"?>
<!-- http://blog.flexexamples.com/2009/03/08/setting-a-label-field-on-a-fxlist-control-in-flex-gumbo/ -->
<FxApplication name="FxList_labelField_test"
xmlns="http://ns.adobe.com/mxml/2009"
backgroundColor="white"
initialize="init();">
<layout>
<BasicLayout />
</layout>
<Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.components.FxList;
private var arrColl:ArrayCollection;
private var list:FxList;
private function init():void {
var arr:Array = [];
arr.push({name:"The", price:0.23});
arr.push({name:"quick", price:1.03});
arr.push({name:"brown", price:0.98});
arr.push({name:"fox", price:1.19});
arr.push({name:"jumps", price:0.28});
arr.push({name:"over", price:0.42});
arr.push({name:"the", price:0.09});
arr.push({name:"lazy", price:0.81});
arr.push({name:"dog", price:0.72});
arrColl = new ArrayCollection(arr);
list = new FxList();
list.labelField = "name";
list.dataProvider = arrColl
list.horizontalCenter = 0;
list.verticalCenter = 0;
addElement(list);
}
]]>
</Script>
</FxApplication>
Setting the the labelField property is also very useful if you are using an XMLListCollection object as a data provider, as seen in the following example:
<?xml version="1.0"?>
<!-- http://blog.flexexamples.com/2009/03/08/setting-a-label-field-on-a-fxlist-control-in-flex-gumbo/ -->
<FxApplication name="FxList_labelField_test"
xmlns="http://ns.adobe.com/mxml/2009"
backgroundColor="white"
initialize="init();">
<layout>
<BasicLayout />
</layout>
<Script>
<![CDATA[
import mx.collections.XMLListCollection;
import mx.components.FxList;
private var xmlListColl:XMLListCollection;
private var list:FxList;
private var nodesXML:XML = <nodes>
<node name="The" price="0.23" />
<node name="quick" price="1.03" />
<node name="brown" price="0.98" />
<node name="fox" price="1.19" />
<node name="jumps" price="0.28" />
<node name="over" price="0.42" />
<node name="the" price="0.09" />
<node name="lazy" price="0.81" />
<node name="dog" price="0.72" />
</nodes>;
private function init():void {
xmlListColl = new XMLListCollection(nodesXML.node);
list = new FxList();
list.labelField = "@name";
list.dataProvider = xmlListColl
list.horizontalCenter = 0;
list.verticalCenter = 0;
addElement(list);
}
]]>
</Script>
</FxApplication>
This entry is based on a beta version of the Flex Gumbo SDK and therefore is very likely to change as development of the Flex SDK continues. The API can (and will) change causing examples to possibly not compile in newer versions of the Flex Gumbo SDK.
