If you have an arrayCollection of custom Objects, how do you access them?
none of the following ways work:
Code:
<s:ComboBox dataProvider="{productService.products}"/>
//result: a combo with lots of [object Product]
//and:
<s:ComboBox dataProvider="{productService.products.getItemAt(0)}"/>
//or
<s:ComboBox dataProvider="{productService.products.getItemAt(0)}" labelField="name"/>
//result in an arror: Implicit coercion of a value with static type Object to a //possibly unrelated type mx.collections:IList.
I confirmed that the ArrayCollection is being populated correctly with the debugger. If you need more:
First I created a ValueObject, for example 'Product' with only 2 properties for simplicity, and a 'buildFromAttributes' function, because I plan to populate that ValueObject with XML data:
[Product.as]
Code:
package valueObjects
{
public class Product
{
private var name:String;
private var cost:String;
}
...
public static function buildFromAttributes(data:XML):Product
{
var prod:Product = new Product(data.@name, data.@cost);
return prod;
}
..
I created a
products ArrayCollection of
Product, and populated it with XML data from the server and everything is working OK since now, debugger says.
Now I want to display those elements in a ComboBox or in a List, but I have not been able. in the
[mainFile.mxml]
Code:
...
<fx:Declarations>
//Here is the service that populates the ArrayCollection, not included here.
<services:ProductService id="productService"/>
</fx:Declarations>
...
protected function creationCompleteHandle(event:FlexEvent):void
{
productService.send();
}
...
can you help me show the custom Product Objects from the arrayCollection in a comboBox or in a List by name or even one in a label?