User Guide

Using the CellRenderer API 111
Using the CellRenderer API
You must write a class with four methods (CellRenderer.getPreferredHeight(),
CellRenderer.getPreferredWidth(), CellRenderer.setSize() and
CellRenderer.setValue()) that the list-based component uses to communicate with the
cell (if the class extends UIObject, you can use
size() instead of
CellRenderer.setSize()). The class must be specified in the AS 2.0 Class text box in the
Linkage Properties dialog box of a movie clip symbol in your Flash application.
You can look at the CheckCellRenderer class that implements the Cell Renderer API for an
example; it’s located in First Run/classes/mx/controls/cells. Also, see the DataGrid component
documentation for CellRenderer related information, including “DataGrid performance
strategies” on page 256.
There are two methods and a property (
CellRenderer.getCellIndex(),
CellRenderer.getDataLabel(), and CellRenderer.listOwner) that are given
automatically to a cell to allow it to communicate with the list-based component. For
example, suppose a cell contains a check box that, when selected, causes a row to be selected.
The cell renderer needs a reference to the list-based component that contains it in order to call
the component’s
selectedIndex property. Also, the cell needs to know which item index it is
currently rendering so that it can set
selectedIndex to the correct number; the cell can use
CellRenderer.listOwner and CellRenderer.getCellIndex() to do so. You do not need
to implement these ActionScript elements; the cell receives them automatically when it is
placed in the list-based component.