Data Binding an Array in Flex?

Can you do it?  No you can’t.

Not directly anyway – Arrays aren’t something that data binding works with in Flex.  ArrayCollection however, is something you can work with.  To use an Array as a bindable object, you can wrap it in an ArrayCollection.  It’s similar, but not the same as an Array – you can’t push, pull, pop or shift things anymore – you have to work with other methods like addItem or removeItem.

I would’ve liked to find that all of those classic array methods still worked, but what can you do?

,

About James

James is a Senior New Media Developer at MMT Digital, and has BA(Hons) in Design for Interactive Media from the University of Gloucestershire. He loves designing and producing all sorts of website and Flash-related things, as well as prattling on about technologies.Day-to-day he works with Flash, Dreamweaver, Director, Microsoft Office Sharepoint Server 2007 (MOSS) and in his spare time he mucks about in Flex and Wordpress.Follow James on Twitter.

4 Responses to “Data Binding an Array in Flex?”

  1. DavidD 2nd February, 2009 at 2:25 pm # Reply

    The property ArrayCollection.source is the very array that resides inside an AC , thus it allows access to Array methods ( mycollectionAC.source.indexOf(…) ).
    Just experiment with that to see if it’s of any help to you.
    It’s feasible and can maybe be handy but I would advise you to test the limits of this way of doing so, especially if you plan to modify the ArrayCollection items.

    Or then you can replace your source array property with a modified one in your AC. It’s for you to see.

  2. James 2nd February, 2009 at 3:19 pm # Reply

    Oh, that makes a lot of sense! – I can see why they’d want to do it that way. – Cheers!

  3. Bruce 2nd February, 2009 at 10:30 pm # Reply

    Don’t forget that things you do to the array might not show up (since it’s not bindable) and you might need to fire off an event like refresh() on the ArrayCollection if you using the .source property.

  4. Bruce 2nd February, 2009 at 10:33 pm # Reply

    oh yeah, if you’re using a DataService ArrayCollection you might find that the list property is populated instead of the .source, so be careful of that as well.

Leave a Reply

Note: This post is over 3 years old. You may want to check later in this blog to see if there is new information relevant to your comment.