Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > Flex > Flex 2, 3 & 4

 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
Old 01-10-2012, 05:17 PM   #1
artcab
Registered User
 
Join Date: Jan 2012
Posts: 4
Unhappy How to access an ArrayCollection of custom Objects in comboBox?

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?
artcab is offline   Reply With Quote
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:42 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.