How to use associative arrays explore data from XML (Part 2 Use Object)

Nov 30th, 2010 | Posted by Michael

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>

Demo and Source

Originally posted 2010-07-30 03:09:38.

No comments yet.
*

Popular Arichives