User Guide

CellRenderer API 155
Description
Method; takes the values given and creates a representation of them in the cell. This resolves any
difference between what was displayed in the cell and what needs to be displayed in the cell for
the new item. (Remember that any cell could display many values during its time in the list.) This
is the most important CellRenderer method, and you must implement it in every cell renderer.
The
setValue() method is called frequently (for example, when a rollover, a selection, column
resizing, or scrolling occurs). Therefore, you should write
if statements in the body of
setValue() that allow code to run only if a change has occurred. See the “Example” section
below.
If a row is selected and the mouse pointer is over it, the value of the selected parameter is
"highlighted", not "selected". This can cause problems if youre trying to make the cell
renderer behave differently according to whether the row is in a selected state. To test whether the
current row is in a selected state, use the following code:
var reallySelected:Boolean = selected ne "normal" && listOwner.selectedNode ==
item;
Example
The following example shows how to use setValue() and editField() to reference a cell
renderer instance in a grid.
Because a particular cell might not exist on the Stage (for example, if it’s scrolled out of the display
area) or because it might be reused to render another value, you cannot directly reference a
specific cell renderer instance in the grid.
Instead, use the data provider to communicate with a specific cell in the grid. The data provider
holds all the state information about the grid. To display a given cell as enabled or selected
(checked), there should be a corresponding field in the data provider to hold that information.
The
setValue() method of your cell renderer communicates changes in the data provider’s state
to the cell. The following is a
setValue() implementation from a theoretical cell renderer that
renders a check box in the cells:
function setValue(str, itm, sel)
{
/* Assume the data provider has two relevant fields for this cell : checked and
enabled.
The form of such a data provider might look like this:
[
{field1:"DisplayMe", field2:"SomeString", checked:true, enabled:false}
{field1:"DisplayMe", field2:"SomeString", checked:false, enabled:true}
{field1:"DisplayMe", field2:"SomeString", checked:true, enabled:true}
]
*/
// redundancy checking
if (myCheck.selected!=itm.checked){
myCheck.selected = itm.checked;
}