0

I'm new to flex/flash builder, i need to read in data from a text document, then slice it into pieces i set out in my custom class.

all of this so far worked

var theCustomer:Customer=new Customer(name,address,phoneNo,comment,custNo);
custArray.addItem(theCustomer);

So now what i want to do is display only the name from each entry of the array into a combobox - and then on close it will display all the details into a list box

If i just bind the custArray to the combobox it displays name:address:phoneNo:comment:custNo as i set it out, but like i said i want only the name so how do i separate the name from each Customer entry in the array ??

Any help you be awesome and thanks in advance !!!

1
  • As you yourself hinted at, you should use the slice() method of an array. Commented Jun 7, 2013 at 14:07

2 Answers 2

1

If I'm understanding your question correctly, I think you want to set the labelField property on the combobox. This specifies the field in the source data objects to use in the label.

<s:ComboBox dataProvider="{custArray}" labelField="name"/>
Sign up to request clarification or add additional context in comments.

4 Comments

I guess I was too busy typing and didn't notice your answer :) Leaving mine as I added a few extra details... but the OP should accept this, since you did it first :)
No prob - I just had the advantage of three minutes on you! I like your answer since it does have more info.
Thank you for the reply Bill Turner, but it hasn't changed the displayed information in the combobox, it still displays all 5 fields side by side in the drop-down menu, and not filtering the name field.
@Bill Turner as you can see from reading follow ups to this question i hadn't put enough code for the labelField to work, but after fixing the code it does now work again thanks for taking the time to reply in the first place
1

The ComboBox has several ways to specify what it should use as the "label" for each item in the dataProvider:

  • By default, if the elements in the dataProvider has a property named label, and that property contains a String it will display that value.
  • ComboBox has a labelField property that you can use to tell it where to find the "label" for each item. In your case, you could set the labelField to "name"
  • ComboBox has a labelFunction property that allows you to use a function (that you write) to specify what text should be displayed for each item.

I suggest using the the labelField, as that seems the most straight forward in this case:

<s:ComboBox dataProvider="{custArray}" labelField="name" />

11 Comments

Thank you for the reply Sunil D, but it hasn't changed the displayed information in the combobox, it still displays all 5 fields side by side in the drop-down menu, and not filtering the name field.
@SteveAndrews Hmm, maybe you should show the code you're using to instantiate the ComboBox. Does it look like what Bill Turner and I have suggested? Are you using a custom skin for the ComboBox (that declares it's own item renderer for the ComboBox's drop down list)?
<s:ComboBox id="cboExisting" width="407" dataProvider="{custArray}" labelField="name" fontSize="15"/> that is the combobox i'm using. link this is a screenshot of the Air app working and the output with all 5 fields. Thank you for your help as well to all who are helping me
Could anyone else help with this too, kinda pulling my hair out, as it's a little frustrating (as coding sometimes is) :)
The only other thing that comes to mind is that possibly your Customer class has a toString() or some other method that is returning that text. I realized when you experience the problem that Bill Turner and I both suspected, it usually prints "[Object] Object" for each item,. So you must have some code somewhere that is making it print that.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.