"happybrowndog" <webforumsuser@macromedia.com> wrote in message
news:ge2lpp$sju$1@forums.macromedia.com...
> **** UPDATE ****
>
> The solution proposed by atta707 would work, if this was done in the
> overriden
> set() method of a custom itemrenderer. The reason why all states have to
> be
> checked and style set for it is because the itemrenderer is instantiated
> as it
> comes into view when the scrollbar moves the cell into view, as discussed
> here:
> http://www.adobe.com/devnet/flex/art...html?devcon=f1
>
> I apologize for not giving a better example of what I was ultimately
> trying to
> achieve, but it was under the assumption that the particular instance of
> an
> itemrenderer for a column/row coordinate is never "destroyed" once
> created.
>
> However, the approach that Flex developers took makes addressing my actual
> problem difficult. So I will state it here for the first time: What I am
> trying to achieve is to show the user that the user has changed the value
> (to
> any value, not just a particular value) in the cell - for the purpose of
> allowing the user to recognize he has made changes to a particular cell in
> a
> potentially huge grid. This is the reason why I put in logic to the
> itemEditEnd event handler and attempted to access the itemrenderer from
> "outside". However, as stated by Peter Ent in
> http://www.adobe.com/devnet/flex/art...html?devcon=f1,
> "....One thing many people try to do is access an itemRenderer from
> outside of
> the list. For example, you might want to make the cell in the fourth
> column of
> the fifth row in a DataGrid turn green because you've just received new
> data
> from the server. Getting that itemRenderer instance and modifying it
> externally
> would be a huge breech of the Flex framework and component model."
>
> To address my problem, I will need to track which cells (by row and column
> coordinates) have had changes made to them in the container holding the
> datagrid, and this would be done in the itemEditEnd event handler. That's
> simple. Now when the itemrenderer is instantiated, it would need to ask
> the
> container holding the datagrid if this is a cell that has been edited by
> passing along which cell it is referring to (by row and column
> coordinates).
> As itemrenderers are instantiated "on the fly" by a classfactory and
> destroyed
> when they come out of view, I can not see how they can be given a callback
> into
> the container holding the datagrid in an effort to know anything about
> itself
> except its data (a real weakness in the architecture, in my opinion). So
> here
> are my questions which I hope someone can answer to help me solve the
> problem:
>
> 1) how can the custom itemrenderer know which row,column coordinates it
> belongs in?
If you implement IDropInListItemRenderer, you will have access to listData,
which contains this information.
> 2) how can the custom itemrenderer call back into the container that holds
> the
> datagrid?
http://blog.flexmonkeypatches.com/20...togglebuttons/
Let me explain what's going on here. The Flex developers put things in
particular places in the code so that the same segment of code doesn't run
over and over unnecessarily.
When you override set data(), you should then call invalidateProperties(),
which says that when the player enters the next frame, commitProperties
should run. commitProperties is where you should do all of your setting of
properties based on what happened in the set data(). The reason for this is
that the objects you may be trying to set properties on may not exist when
the first call to set data() happens. So, what you're doing is saying "I
know that the data has changed, so at the appropriate moment I want to make
changes in properties based on that." That doesn't sound very logical, but
if you have several properties being set, say listData _and_ data, then it
starts to make more sense... Even ignoring the fact that the objects may not
exist at the first call to set data(), if you do some things based on what
happens in set data() and then undo them based on what happens in set
listData(), how much sense does that make?
Instead, you wait until all property values are known, and then override
commitProperties(), so that when that is called you can do whatever you need
to do in the full knowledge of _all_ the variables that you need set before
you do anything based on what those values are. And if that were all that
were going on, you could go ahead and do your layout there, and that is
where the engineers would have put the layout code for the component.
But...there are already things that are being set in the
super.commitProperties(), and the layout code needs to be able to react to
all the properties that are being set there _and_ in your code--and here's
the important part--you shouldn't have to know what's going on in the super
method so you don't disrupt it with anything in code you put in
commitProperties(), either before or after the super.
So that's where invalidateDisplayList() and updateDisplayList() come in. So
if the changes you make in commitProperties() affect the size, color, or any
other visual property you want to set yourself, you should then override
updateDisplayList() and do those changes there.
For similar reasons, if you change anything in commitProperties (like the
dataProvider of a subcomponent) or updateProperties() that changes the size,
you need to update measure() so that the parent component can make
intelligent choices about how much space to allocate.
Hope this clarifies.
-Amy