0

Im kinda new to the Flex environment and I was wondering how to do this scenario:

My initial code goes like this:

public function displayAllNames(event:ResultEvent):void {

    var result:ArrayCollection  = new ArrayCollection();

    result = event.result as ArrayCollection;

   if (result.length != 0){
       listBox.dataProvider = result;
   }
}

event.result is an ArrayCollection of Person class that has the name attribute

listBox is the id of the List Component in Flex where the names are going to be displayed

When I tried to run the code, the listbox did show something. But instead of the names, it displayed object Object all throughout. It seems like I still have to do something with event.result first so that it would be an ArrayCollection of Person class.

albfan
  • 12,542
  • 4
  • 61
  • 80
Israel Sato
  • 199
  • 1
  • 2
  • 12

1 Answers1

0

You need to set the labelField of your ComboBox, try this

Assuming Person has a visible name property,

public class Person(){
   public var name:String = "User 1";
}

You can tell your ListBox to use that property to populate its label field by using the labelField property

if (result.length != 0){
   listBox.labelField = "name";
   listBox.dataProvider = result;
}

By default I believe is set to "label", if that property is not found it will use Object.toString() that's where [Object object] is coming from.

due to this its also possible to override, or simply include, the toString method in your data provider class and not change the list's labelField

overide pubic function toString():String{
    return "this will become your label field";
}
francis
  • 5,889
  • 3
  • 27
  • 51