[flexcoders] Re: Trying to use a mx:model populated by XML file and then as source to ArrayCollection to populate datagrid

2006-12-14 Thread Christina Burnham
--- In flexcoders@yahoogroups.com, Doug Lowder [EMAIL PROTECTED] 
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
  anTypeCat/anType
  anNameGoldenBoy/anName
  anLivingYes/anLiving
  /pet
/animals
  
  Thanks in advance
  Christina
 





[flexcoders] Re: Trying to use a mx:model populated by XML file and then as source to ArrayCollection to populate datagrid

2006-12-14 Thread Doug Lowder
(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
   anTypeCat/anType
   anNameGoldenBoy/anName
   anLivingYes/anLiving
   /pet
 /animals
   
   Thanks in advance
   Christina
  
 





[flexcoders] Re: Trying to use a mx:model populated by XML file and then as source to ArrayCollection to populate datagrid

2006-12-12 Thread Christina Burnham
--- In flexcoders@yahoogroups.com, Doug Lowder [EMAIL PROTECTED] 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 ] }/

Ah! Thanks!! That did the trick Yay!!!
 




[flexcoders] Re: Trying to use a mx:model populated by XML file and then as source to ArrayCollection to populate datagrid

2006-12-12 Thread Doug Lowder
I missed the syntax problem but, interestingly enough, the app works 
without the mx:Array tag - although I'm not sure why.  Tracy is 
correct, the columns property is an Array so it should contain an  
mx:Array tag when declared in mxml.

--- In flexcoders@yahoogroups.com, Tracy Spratt [EMAIL PROTECTED] 
wrote:

 You do not have an option with the syntax.  It must be:
 
 mx:columns
 
 mx:Array
 
 mx:DataGridColumn
 
 ...
 
  
 
 Tracy
 
  
 
 
 
 From: flexcoders@yahoogroups.com 
[mailto:[EMAIL PROTECTED] On
 Behalf Of Burnham, Christina
 Sent: Monday, December 11, 2006 6:01 PM
 To: flexcoders@yahoogroups.com
 Subject: [flexcoders] Trying to use a mx:model populated by XML 
file and
 then as source to ArrayCollection to populate datagrid
 
  
 
 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
 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
 anTypeCat/anType
 anNameGoldenBoy/anName
 anLivingYes/anLiving
 /pet
 /animals
 
 Thanks in advance
 Christina





[flexcoders] Re: Trying to use a mx:model populated by XML file and then as source to ArrayCollection to populate datagrid

2006-12-12 Thread Christina Burnham
--- In flexcoders@yahoogroups.com, Doug Lowder [EMAIL PROTECTED] 
wrote:

 I missed the syntax problem but, interestingly enough, the app 
works 
 without the mx:Array tag - although I'm not sure why.  Tracy is 
 correct, the columns property is an Array so it should contain an  
 mx:Array tag when declared in mxml.
 

I added the mx:array even though it works (with more than pet in the 
file) without it, and it still worked, but I was hoping it would 
solve solve the problem I get when there is only one pet in the file. 
Before it was just nothing, but since I added Tracy's mx:array it 
pops up an error window in the browser that says this..
TypeError: Error #1034: Type Coercion failed: cannot convert 
mx.utils::[EMAIL PROTECTED] to Array.
at MethodInfo-505()
at Function/http://adobe.com/AS3/2006/builtin::apply()
at mx.binding::Binding/mx.binding:Binding::wrapFunctionCall()
at mx.binding::Binding/::innerExecute()
at Function/http://adobe.com/AS3/2006/builtin::apply()
at mx.binding::Binding/mx.binding:Binding::wrapFunctionCall()
at mx.binding::Binding/execute()
at _popFromXmlFileWatcherSetupUtil/setup()
at popFromXmlFile/initialize()
at 
mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal:
:childAdded()
at mx.managers::SystemManager/::initializeTopLevelWindow()
at mx.managers::SystemManager/::frameEndHandler()


(This the the source) 
?xml version=1.0 encoding=utf-8?
mx:Application xmlns:mx=http://www.adobe.com/2006/mxml; 
layout=absolute

!-- populate datagrid from xml file --
mx:Model id=animalList source=pets.xml/

mx:ArrayCollection id=anListAC source={animalList.pet}/

mx:DataGrid x=75 y=98 dataProvider = {anListAC}  
mx:columns
  mx:Array
mx:DataGridColumn headerText=Type 
dataField=anType/
mx:DataGridColumn headerText=Name 
dataField=anName/
mx:DataGridColumn 
headerText=Living dataField=anLiving/  
   /mx:Array  
/mx:columns 
/mx:DataGrid
/mx:Application






[flexcoders] Re: Trying to use a mx:model populated by XML file and then as source to ArrayCollection to populate datagrid

2006-12-12 Thread Doug Lowder
That issue is because pets.xml is generating an Object when there is 
a single item, instead of an Array (which it will do when there ai 
more than one pet defined).  Take a look at 
mx.utils.ArrayUtil.toArray() is the docs for some code that will 
ensure you are always dealing with an Array.

- Doug

--- In flexcoders@yahoogroups.com, Christina Burnham 
[EMAIL PROTECTED] wrote:

 --- In flexcoders@yahoogroups.com, Doug Lowder douglowder@ 
 wrote:
 
  I missed the syntax problem but, interestingly enough, the app 
 works 
  without the mx:Array tag - although I'm not sure why.  Tracy 
is 
  correct, the columns property is an Array so it should contain 
an  
  mx:Array tag when declared in mxml.
  
 
 I added the mx:array even though it works (with more than pet in 
the 
 file) without it, and it still worked, but I was hoping it would 
 solve solve the problem I get when there is only one pet in the 
file. 
 Before it was just nothing, but since I added Tracy's mx:array it 
 pops up an error window in the browser that says this..
 TypeError: Error #1034: Type Coercion failed: cannot convert 
 mx.utils::[EMAIL PROTECTED] to Array.
   at MethodInfo-505()
   at Function/http://adobe.com/AS3/2006/builtin::apply()
   at mx.binding::Binding/mx.binding:Binding::wrapFunctionCall()
   at mx.binding::Binding/::innerExecute()
   at Function/http://adobe.com/AS3/2006/builtin::apply()
   at mx.binding::Binding/mx.binding:Binding::wrapFunctionCall()
   at mx.binding::Binding/execute()
   at _popFromXmlFileWatcherSetupUtil/setup()
   at popFromXmlFile/initialize()
   at 
 
mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal
:
 :childAdded()
   at mx.managers::SystemManager/::initializeTopLevelWindow()
   at mx.managers::SystemManager/::frameEndHandler()
 
 
 (This the the source) 
 ?xml version=1.0 encoding=utf-8?
 mx:Application xmlns:mx=http://www.adobe.com/2006/mxml; 
 layout=absolute
 
 !-- populate datagrid from xml file --
   mx:Model id=animalList source=pets.xml/
   
 mx:ArrayCollection id=anListAC source={animalList.pet}/
 
   mx:DataGrid x=75 y=98 dataProvider = {anListAC}  
   mx:columns
 mx:Array
   mx:DataGridColumn headerText=Type 
 dataField=anType/
   mx:DataGridColumn headerText=Name 
 dataField=anName/
   mx:DataGridColumn 
 headerText=Living dataField=anLiving/
  /mx:Array  
   /mx:columns 
   /mx:DataGrid
 /mx:Application





[flexcoders] Re: Trying to use a mx:model populated by XML file and then as source to ArrayCollection to populate datagrid

2006-12-11 Thread Doug Lowder
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 ] }/


--- In flexcoders@yahoogroups.com, Burnham, Christina 
[EMAIL PROTECTED] 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
 anTypeCat/anType
 anNameGoldenBoy/anName
 anLivingYes/anLiving
 /pet
   /animals
 
 Thanks in advance
 Christina