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 !!!

Steve Andrews
  • 111
  • 2
  • 2
  • 8
  • As you yourself hinted at, you should use the [slice()](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Array.html#slice()) method of an array. – Garry Wong Jun 07 '13 at 14:07

2 Answers2

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"/>
Bill Turner
  • 980
  • 1
  • 6
  • 23
  • 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 :) – Sunil D. Jun 07 '13 at 20:41
  • No prob - I just had the advantage of three minutes on you! I like your answer since it does have more info. – Bill Turner Jun 07 '13 at 21:00
  • 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. – Steve Andrews Jun 08 '13 at 02:21
  • @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 – Steve Andrews Jun 10 '13 at 04:22
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" />
Sunil D.
  • 17,983
  • 6
  • 53
  • 65
  • 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. – Steve Andrews Jun 08 '13 at 02:20
  • @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)? – Sunil D. Jun 08 '13 at 05:40
  • `` that is the combobox i'm using. [link](http://gyazo.com/3f41efba06c6b0a5ead1518eee02525a) 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 – Steve Andrews Jun 08 '13 at 07:31
  • Could anyone else help with this too, kinda pulling my hair out, as it's a little frustrating (as coding sometimes is) :) – Steve Andrews Jun 09 '13 at 14:41
  • 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. – Sunil D. Jun 09 '13 at 20:34
  • Yes your right, in the class definition i do have a toString returning it exactly like it displays. So how would i go about changing that ?? – Steve Andrews Jun 10 '13 at 00:16
  • would it be as simple as removing the toString from the constructor ?? – Steve Andrews Jun 10 '13 at 00:19
  • Well, you could modify the `toString()` function so it returns the proper text. Or delete the toString() method. But something is not right. I just reproduced what you're seeing (the output of toString() is used), but if I do `labelField="name"` in my `ComboBox` it works properly. So not sure why your case is different... – Sunil D. Jun 10 '13 at 03:14
  • D really?? damn maybe somewhere else i have an error or put something in where it shouldn't be, because i'm new to programming in general it's harder to spot the errors – Steve Andrews Jun 10 '13 at 03:44
  • It all makes sense now based on [this answer](http://stackoverflow.com/a/17016328/398606) to another question of yours... Your Customer class doesn't have a getter method for the "name" property, so doing `labelField="name"` doesn't work and the ComboBox just uses the value from the `toString()` method instead. If you add the getter method for `name`, then the `labelField` approach should work. – Sunil D. Jun 10 '13 at 03:48
  • Sweet that is now working woohoo Thank you so much @Sunil for taking the time to answer my question, and continuing help – Steve Andrews Jun 10 '13 at 04:15