View comments | RSS feed

Arrays of objects

When a component has a property that takes an Array of objects as its value, you can represent the property in MXML using child tags, as the following example shows:

<mynamespace:MyComponent>
   <mynamespace:nameOfProperty>
      <mx:Array>
         <objectType prop1="val1" prop2="val2"/>
         <objectType prop1="val1" prop2="val2"/>
         <objectType prop1="val1" prop2="val2"/>
      </mx:Array>
   </mynamespace:nameOfProperty>
</mynamespace:MyComponent>

The component in the following example contains an Array of ListItem objects. Each ListItem object has properties named label and data.

<mynamespace:MyComponent>
   <mynamespace:dataProvider>
      <mx:Array>
         <mynamespace:ListItem label="One" data="1"/>
         <mynamespace:ListItem label="Two" data="2"/>
      </mx:Array>
   </mynamespace:dataProvider>
</mynamespace:MyComponent>

The following example shows how you specify an anonymous object as the value of the dataProvider property:

<mynamespace:MyComponent>
   <mynamespace:dataProvider>
      <mx:Array>
         <mx:Object label="One" data="1" />
         <mx:Object label="Two" data="2" />
      </mx:Array>
   </mynamespace:dataProvider>
</mynamespace:MyComponent>

Version 1.5

Comments


kagnu said on Apr 7, 2005 at 10:03 PM :
Under "Arrays of objects" at
http://livedocs.macromedia.com/flex/15/flex_docs_en/wwhelp/wwhimpl/js/html/wwhelp.htm
the examples don't match the FLEX sample program, which has
-------------------------------------------
<mx:Array id="coffeeArray">
<mx:Object>
<label>Red Sea</label>
<data>Smooth and fragrant</data>
</mx:Object>
<mx:Object>
<label>Andes</label>
<data>Rich and pungent</data>
</mx:Object>
<mx:Object>
<label>Blue Mountain</label>
<data>Delicate and refined</data>
</mx:Object>
</mx:Array>
-------------------------------------------
e.g., no quotes for labels or data;
BUT ALSO
I've not been able to get past this error message:
"Error /firstapp.mxml:3
The markup in the document following the root element must be well-formed."
where the 1st 7 lines in the little example program are
------------------------------------------
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml"/>
<mx:Array id="traitsArray">
<mx:Object>
<label>Personable</label>
<data>Gets along with every type of employee</data>
</mx:Object>
------------------------------------------
help would be appreciated.
thx,
kagnu
smgilson said on Apr 11, 2005 at 5:43 PM :
You can define an array using tag attributes, as the example in the doc shows, or using tag properties, as you have shown. When using tag properties, you do not need the quotes around the value.

Your error is because you do not have a closing </mx:Array> tag at the end of your example, not a closing </mx:Application> tag.

Stephen
smgilson said on Apr 11, 2005 at 5:49 PM :
In the previous comment, I meant to say 'nor' a closing </mx:Application> tag.

Stephen

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flex/15/flex_docs_en/00000033.htm