Item renderers are recycled in Flex for better performance, so you either need an event on the itemRenderer component, or else bind itemRenderer component properties and styles to the data and modify those fields in the data.
If this post answers your question or helps, please mark it as such.
Greg Lafrance - Flex 2 and 3 ACE certified
Flex / AIR Development, Training, and Support Services
Register a event on ItemRenderer? And how to retrivie those propertis from genereted by item renderer event?
I'm not sure if I'm understand you correctly.
Could you give me piece of code Greg
and thanks for answer
I think first I need a more clear description of what you are trying to achieve. How would you like to style or otherwise change the selected elements in the List?
I'm building some kind of Internet text communicator.
User have got a friends list with his contacts. When user select a friend I want to
- show some additional info about this friend
- show few actions like (talk, add to talk, delete etc..)
This elements will take some space in item container so I need to increase size of that item container.
How do you think, add child is better idea to put new elements into selected item or default make it invisible and manipulate only visible property?
Still not clear on exactly what should change in the UI. Describe the UI changes precisely, perhaps describing the user workflow.
Read up on item renderers and repeaters.
OK, I try to explain it as clear as I can.
On a user event like changing selected item of a list I want to:
- change size (height) of that selected by user item
- change label font of that selcted by user item
- add child mxml component to that selected by user item
After user select another item of list I want to restore changes of previous item to default and apply this changes on next item (currently selected by user).
Referring to piece of code in my first post:
For instance, if default height of VBox item is 20 I want to set height property to 50 of selected item if event 'change' or 'click' will occur.
Hope, I express it clearly
1 person found this helpful
Anytime you want to affect one of the items in a Flex control like List that recycles itemRenderers, you need to operate on the data. So the data should have fields for height and label font, and a boolean like "selected". Then create an item renderer that accesses these data fields and renders appropriately.
For the part where you want to add a child, just have it always be there, but set the visible and includeInLayout properties false unless the "selected" boolean field in the data is true, and set that data field to true when an item is selected.
I done what you advice me Greg but it's still doesn't work
I add to objects which populates list a bindable property height and in item renderer I grab this value and setting as height property of UI component, but it's not reflected at runtime.
I'm sure that I retrive height value from objects because I'm printing this value in each item to check it.
After ItemRenderer render items I affecting height value in first item. Value in label is changing but it's still not reflected in UI Vbox height.
If I put static height value to VBox it's reflected in layout but that don't satisfied me. I have to dynamically manipulate height at runtime.
Thanks for help
Looking forward to see answers
I found solution !
Well it's not so brilliant solution but it's work.
The point is that changing properties of parent component in Component in ItemRenderer are not reflected in UI. Only changes in children elements are reflected in UI. In my case (post #1) it's label component.
However it's works.
Thank you Greg !