User Guide
112 CellRenderer API
Simple cell renderer example
This section presents an example of a cell renderer that displays multiple lines of text in a cell.
The following tutorial shows how to create a cell renderer class that displays multiple lines of
text in the cells of a DataGrid component.
The completed files, MultiLineCell.as and CellRenderer_tutorial.fla are located at
www.macromedia.com/go/component_samples.
Creating the MultiLineCell cell renderer class
A cell renderer class must implement the following methods:
■ CellRenderer.getPreferredHeight()
■ CellRenderer.getPreferredWidth()
The CellRenderer.getPreferredWidth() method is necessary for Menu components
or DataGrid headers only; otherwise, comment it out of the code, as shown in the
example.
■ CellRenderer.setSize()
If a cell renderer class extends UIObject, use implement size() instead, as shown in this
example.
■ CellRenderer.setValue()
A cell renderer class must also declare the methods and property received from the List class:
■ CellRenderer.getCellIndex()
■ CellRenderer.getDataLabel()
■ CellRenderer.listOwner
The following steps show how to create an ActionScript 2.0 cell renderer class file called
MultiLineCell.as and link it to a new movie clip symbol in a new Flash document. Then, you
can add a DataGrid component to the Flash document library. On the first frame, you add
ActionScript that creates the DataGrid dynamically and assigns the MultiLineCell class as the
cell renderer for one of its columns:
To create the multiLineCell cell renderer class:
1. In Flash, select File > New > ActionScript File (not Flash Document). Save the document
as MultiLineCell.as.
2. Enter the following code into MultiLineCell.as:
// ActionScript 2.0 class.
class MultiLineCell extends mx.core.UIComponent
{
private var multiLineLabel; // The label to be used for text.