(My last post didn't seem to get through, so I'll try again...)

Flex will interpret the XML as an Object when a single item is 
defined, but as an Array when there are multiple items.  To ensure 
you are always dealing with an Array, you can import 
mx.utils.ArrayUtil and use the static function ArrayUtil.toArray() 
like so:

  <mx:ArrayCollection id="anListAC"
    source="{ ArrayUtil.toArray( animalList.pet } }"/>

Search the docs for ArrayUtil.toArray() for some examples.

HTH,
Doug

--- In flexcoders@yahoogroups.com, "Christina Burnham" 
<[EMAIL PROTECTED]> wrote:
>
> --- In flexcoders@yahoogroups.com, "Doug Lowder" <douglowder@> 
> wrote:
> >
> > Change the model property referenced by the ArrayCollection 
source 
> > to "animalList.pet" and specify it as an array (an Object is 
> > returned when there is only a single item), and it should work:
> > 
> > <mx:ArrayCollection id="anListAC"
> >     source="{ [ animalList.pet ] }"/>
> > 
> 
> Uh oh, if there is only one pet in the file it works with the 
> brackets []. If there is more than one pet it doesn't work unless 
you 
> take them away.. what's going on here? 
> 
> 
> > 
> > --- In flexcoders@yahoogroups.com, "Burnham, Christina" 
> > <christina.burnham@> wrote:
> > >
> > > I'm learning Flex 2 and I'm trying to get this example to work 
> and 
> > I'm
> > > about to give up.  My datagrid comes up empty. It works fine 
when 
> > I hard
> > > code the data in an array inside a datarovider within the 
> > mx:DataGrid
> > > tags I also tried putting the DataGridColumns inside of Array 
> > tags. No
> > > joy, nothing but empty datagrid. 
> > > 
> > > I'm running on XP using IE and using Flex 2 in the Eclipse IDE.
> > > 
> > > <?xml version="1.0" encoding="utf-8"?>
> > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
> > > layout="absolute">
> > >     <mx:Model id="animalList" source="pets.xml">
> > >     </mx:Model>
> > >     <mx:ArrayCollection id="anListAC"
> > > source="{animalList.animals.pet}"/>
> > >    <mx:DataGrid x="75" y="98" dataProvider = "{anListAC}">  
> > >        <mx:columns>
> > >              <mx:DataGridColumn headerText="Type" 
> > dataField="anType"/>
> > >             <mx:DataGridColumn headerText="Name" 
> > dataField="anName"/>
> > >             <mx:DataGridColumn headerText="Living"
> > > dataField="anLiving"/>    
> > >       </mx:columns>
> > >     </mx:DataGrid>
> > > </mx:Application> 
> > > 
> > > This is the XML file:
> > > 
> > > <?xml version="1.0"?>
> > >   <animals>
> > >     <pet>
> > >         <anType>Cat</anType>
> > >         <anName>GoldenBoy</anName>
> > >         <anLiving>Yes</anLiving>
> > >     </pet>
> > >   </animals>
> > > 
> > > Thanks in advance
> > > Christina
> > >
> >
>


Reply via email to