A serious case of 'Wobble You Tea Eff'
Ok. I’ve seen some weird shit in my days, but this post that i stumbled upon from Aral Balkan has completely confuckulated me.
I was doing a bit of research on finding the created children inside of a Repeater component. Now, the Repeater component is extremely useful but it can be one helluva irritating component to work with. I dug down into the Flex source and found a variable in there (an array called createdComponents) that set off those heaven bells (you know… like when the clouds part and angels descend in the movies)… Alas, it’s a protected variable!!! Noooooooooooooooooooooooo!
So where to now? Do i edit the source and recompile Flex and risk stuffing something up (not mention wasting precious, fleeting time) or do i try and find another solution?
In my days as a Flex developer, i’ve used the Repeater component several times and i always find a way around the inability to get an array of created components (doesn’t it seem logical to include a function for that??). But the solutions i’ve found were all dirty and hackerish, and everytime i use them i feel like i’m coming out of parliament (dirty, oh so dirty)… and then, Mr Balkan comes along and completely saves my mental hygiene, but it’s left me with a serious case of the wobble-you-tea-effs.
What he has done is given each repeated component an id (which seems pointless since one would imagine that it would be of no use since each repeated component is the same) and from that id, a global array gets created out of nowhere (henceforth referred to as the pulling an array out of an orifice method) and you can then access the created components using that id. Odd
, deeply deeply odd
(unless i’m missing something that somebody can point out).
Here’s an example:
1 2 3 4 5 6 7 8 9 | <mx:Array id="someArr"> <mx:String>Button A</mx:String> <mx:String>Button B</mx:String> <mx:String>Button C</mx:String> </mx:Array> <mx:Repeater id="repeater" dataProvider="{someArr}" recycleChildren="true"> <mx:Button id="buttons" label="{repeater.currentItem}"/> </mx:Repeater> |
And then you can access the buttons variable as an array! Each element in the array refers to each component repeated by the Repeater component.
Strange…
Props to Aral Balkan for helping me out!
| Print article | This entry was posted by Danny Kopping on April 2, 2009 at 1:31 pm, and is filed under ActionScript 3.0, Flex. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |