views:

39

answers:

3

I have an itemRenderer for a list where I'm just displaying items and their details respectively. I want to keep the details invisible and have a button,Show Details, in my main mxml file which when clicked would make the details visible.

So, my problem is in the clickHandler how can I access the details property within the itemRenderer from the main mxml?

Thanks in advance for your help

A: 

I would have a Boolean on the main which is what the itemRenderer keys off of. Accessing the itemRenderers of a list is not receommended because they are recycled, and operations cannot be guaranteed.

For an explanation see http://www.adobe.com/devnet/flex/articles/itemrenderers_pt1.html

adamcodes
A: 

There are a few ways to approach this.

One is to use a global Singleton object that contains the "ShowDetails" value. Every itemRenderer can access that object and change it's settings. Cairngorm's ModelLocator is one example of a singleton that is commonly used in this way. I believe swiz has something similar. You could also roll your own if needed.

You could try to extend the List class The List keeps itemRenderers in an array, which I believe is protected. You'll have to extend the List, and make this protected array public. Then you'll be able to access the list of itemRenderers and modify properties on them directly.

However, I'm not sure I would recommend either approach. An itemRenderer really should choose what to display based on the data it is displaying; not some global variable. Can you change the objects in your dataProvider and have the itemRenderer update accordingly? It is a third option; although I'm not sure if it is any better, or worse, than the previous two approaches.

www.Flextras.com
A: 

Hi

You could have a variable in the DataProvider array called 'show' thats set to false. In the itemrenderer bind the visible property of the details component to data.show.

When the show button is pressed, traverse the dataProvider array, and set the 'show' property to true. This will work

Bish

Brian Bishop
I was going to suggest a field in the dataprovider, but since I interpreted the question as all records, I figured one variable to control them all.
adamcodes