Flex, Array, ArrayCollection

I was working on some Flex stuff this morning, and got hung up on a data binding problem. 

Data binding is one of Flex’s strongest features.  It lets you simply say “this value is bound to that”, so you can do something like have a label’s text be bound to a field in your data model, so that if the model changes, the view is updated automatically.

Here’s what I had done:

// ActionScript code
class MyFoo
{
  var myItems:Array = new Array();
}

<!– MXML –>
<mx:List dataProvider=”{myFooInstance.myItems}”/>

I tried binding to both a ComboBox and a List.  When I bound to the ComboBox, I could see the items in the myItems array when I dropped down the combo box, but they never showed up in the list.

Turns out the problem is that when you bind to an Array, you’re binding to the array field itself, not to the items in the array.  If I’d created a new array and assigned it to myItems then the List would have populated, but because I was just adding items to the myItems array, they never showed up.

The solution is simple:  Use an ArrayCollection instead of an Array.  ArrayCollection is designed to be bound to.

4 Responses to “Flex, Array, ArrayCollection”

  1. Tom Says:

    Yes it’s true ! And all Flex newbies have had this problem one time -;) If you want use Array, override push and pop functions in order to refresh the UI part but with ArrayCollection all is “automatic” !

  2. naholyr Says:

    Sorry for exhuming an old post, and maybe it’s a bug in the new Flex version, but I’m a newbie and cannot understand why ArrayCollection properties don’t seem to be bound anymore :
    In the following example, Label is never updated :(

    import mx.collections.ArrayCollection;
    [Bindable] public var array:ArrayCollection = new ArrayCollection([0,0]);

  3. srikanth Says:

    Hello friend,

    Label text value gets updated if an array collection gets updated. see below example.

  4. Goran Says:

    I have problem wich is probbably related to this “array thing”. I am newbee, and this is what I want to do.
    1. I created RemoteObject, and get array of object from database.
    2. I have resultHandler function that take information from this array of object, by extracting just certain attributes, and putting this in array wich is populated OK, i get trace result of this array. Problem is :

    3. Now I am trying to Bind this array in getResultHandler function with dataProvider of repeater components. How can I bind this two components, or I need to use some kind of setter function … and if I do, any idea.

    tx

Leave a Reply

 




 
buy cheap Endep online buy cheapest Endep and Endep how to order Amitriptyline online without prescription buy Amitriptyline without rx from us pharmacy online Amitriptyline purchase purchase online prescription Amitriptyline without purchasing Amitriptyline online without prescription order generic Amitriptyline buy Endep no prescriptions how to order Endep online without prescription comprare Endep generico Endep online buy Endep in england buy cheap Endep online free consult Endep purchased online without prescription what is Endep Endep tabletten buy Endep no perscription cod Endep non rx fedex overnight free want to buy Anafranil in usa Aricept overdose buy discount Aricept on line Aricept buy Aricept online Aricept order buy Aricept pills Nizoral suppliers cheap order rx Nizoral canada Nizoral order Nizoral usa cod comprar Nizoral generico buy Nizoral 200 mg buy cheap Nizoral under without rx buy cheap Nizoral with dr. prescription Prozac 200 mg buy Lisinopril australia el Nizoral generico buy Lisinopril tablets without rx next day delivery Lisinopril with no script buy Lisinopril c o d purchase arimidex no scams order Arimidex order amex Arimidex canadian pharmacy buy Arimidex without doctor order rx free Arimidex buy Abilify with american express buy Abilify cod order Finpecia without a prescription cheap order rx Finpecia purchase Famvir no visa online without prescription buy Famvir paypal without rx buy Famvir without Famvir without prescription medications Famvir without persription purchase Famvir online no membership overnight shipping Famvir no physician approval Amitriptyline purchase order Amitriptyline free next day airAmitriptyline on line Valtrex no rx needed cod accepted buy next day Fluoxetine buy Fluoxetine line purchase Fluoxetine cod delivery buy Fluoxetine 20 mg purchase Fluoxetine buy cheap Fluoxetine under without rx purchase Fluoxetine visa without prescription Fluoxetine by mail Fluoxetine for pets Fluoxetine 10mg Amitriptyline purchase online how to order Famvir online without a rx Prozac Amitriptyline no perscription Famvir next day purchase Anafranil no prescription cheap buy cheapest Anafranil next day delivery on Anafranil saturday Anafranil buy Anafranil buy Anafranil overnight where to purchase Anafranil no prescription no fees Anafranil drug buy Lisinopril where Lisinopril buy on line order Lisinopril online no membership overnight shipping no prescription required for Lisinopril order maxalt cash on delivery Maxalt from canada buy cheapest Maxalt purchase Maxalt visa without prescription buy Maxalt uk Maxalt 10 mg purchase Maxalt no visa online without prescription purchase generic Lisinopril online Lisinopril no prescription to buy maxalt order online no membership overnight how to get a arimidex rx Aricept without a perscription fedex Aricept overnight without a prescription Donepezil prescription order buy genuine Aricept Aricept uk sales prescription Proscar buy Proscar pay cod Maxalt apotheke buy no perscription Proscar purchase Proscar online buy cheap fedex Prednisone maxalt with no presciption buy Maxalt shipped cod Proscar online Prednisone order buy Amitriptyline with amex Accutane 40 mg delivered overnight buy brand Accutane 40 mg Accutane 40 mg orderd online without prescription where to purchase generic Accutane 40 mg online without a rx how to get 40 mg Accutane without next day delivery 40 mg Accutane with no script buy Amitriptyline online Accutane 40 mg online no prescription buy Accutane 40 mg online us pharmacy Accutane 40 mg best buy buy Accutane 40 mg c o d order 40 mg Accutane cash on delivery no presciption 40 mg Accutane