How to use associative arrays explore data from XML (Part 2 Use Object)
If you don’t like use associative arrays ,use Object instead of it!!
Following example will show you how (same XML and Component as Part1)
Associative_arrays_Example2.mxml (use Object)
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:comp="comp.*"
initialize="application1_initializeHandler(event)" viewSourceURL="srcview/index.html">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.collections.ArrayList;
import mx.events.FlexEvent;
[Bindable]
private var cellPhoneDB:ArrayCollection;
[Bindable]
private var searchDB:ArrayList=new ArrayList();
protected function application1_initializeHandler(event:FlexEvent):void
{
var sourceArray:Array=this.cellPhoneData.product as Array;
cellPhoneDB=new ArrayCollection(sourceArray);
var obj:Object=new Object();
for (var i:int; i < sourceArray.length; i++)
{
obj[sourceArray[i].series]=sourceArray[i].series;
}
this.searchDB.addItem("All");
for each (var val:String in obj)
{
this.searchDB.addItem(val);
}
}
]]>
</fx:Script>
<fx:Declarations>
<fx:Model source="assets/catalog.xml"
id="cellPhoneData"/>
</fx:Declarations>
<comp:MyTopBar searchData="{searchDB}"
title="Cell Phone Demo"
id="topBar"/>
</s:Application>
Originally posted 2010-07-30 03:09:38.


