Flex ArrayCollections are great when using them as data providers for datagrids, lists etc.
I used to load xml files with HTTPService and store the result event in an ArrayCollection that I then used as a data provider for my components.
Here’s a typical example:
< ?xml version="1.0" encoding="utf-8"?> <mx:application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white" creationComplete="init()" viewSourceURL="srcview/index.html"> <mx:script> < ![CDATA[ import mx.collections.ArrayCollection; import mx.rpc.events.ResultEvent; [Bindable] private var dataProv : ArrayCollection = new ArrayCollection(); private function init() : void { calendarService.send(); } private function calendarServiceResult( event : ResultEvent ) : void { dataProv = event.result.events.event; } ]]> </mx:script> <mx:datagrid id="dg" dataProvider="{dataProv}"></mx:datagrid> <mx:httpservice id="calendarService" url="http://www.popamihai.com/flex-files/ArrayCollectionOfOneElementAsDataProvider/calendar.xml" result="calendarServiceResult( event )"></mx:httpservice> </mx:application> |
The xml file calendar.xml has the following structure:
<events> <event> <date>13-07-2010</date> <starthour>01</starthour> <category>Aniversary</category> </event> <event> <date>12-07-2010</date> <starthour>02</starthour> <category>Meeting</category> </event> <event> <date>21-07-2010</date> <starthour>03</starthour> <category>To Do</category> </event> </events> |
As long as the xml files has more then one element everything works fine. Here’s the resulting SWF for this application:
Read the rest of this entry »