Psyked *
it’s easy once you know how.Data Binding an Array in Flex?
Posted by James - 02/02/09 at 10:02:35 amCan 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?
February 2, 2009 | In Flex | 4 Comments



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.
Comment by DavidD — 2 February 2009 #
Oh, that makes a lot of sense! – I can see why they’d want to do it that way. – Cheers!
Comment by James — 2 February 2009 #
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.
Comment by Bruce — 2 February 2009 #
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.
Comment by Bruce — 2 February 2009 #