Mega Code Archive

 
Categories / Flex / Data Model
 

Converting an MXML data model into an ArrayCollection

<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"     creationComplete="myAC = new ArrayCollection(myData.book);">     <mx:Script>                      import mx.collections.ArrayCollection;                          [Bindable]             private var myAC:ArrayCollection;                          private function formatData(item:Object):String             {                 return item.title + "," + item.author;             }            </mx:Script>          <mx:Model id="myData">         <rootTag>             <book>                 <title>A</title>                 <author>B</author>             </book>             <book>                 <title>C</title>                 <author>D</author>             </book>         </rootTag>     </mx:Model>          <mx:ArrayCollection source="{myData.book}" id="myACC" />          <mx:List id="myList" dataProvider="{myACC}" labelFunction="formatData" />      </mx:Application>