User Guide

CellRenderer API 147
Simple cell renderer example
This section presents an example of a cell renderer that displays multiple lines of text in a cell.
A cell renderer class must implement the following methods:
CellRenderer.getPreferredHeight()
CellRenderer.getPreferredWidth()
This method is necessary only for Menu components; otherwise, comment it out of the code,
as in the example.
CellRenderer.setSize()
If a cell renderer class extends UIObject, implement size() instead.
CellRenderer.setValue()
A cell renderer class must also declare the methods and property received from the List class:
CellRenderer.getCellIndex()
CellRenderer.getDataLabel()
CellRenderer.listOwner
To test this cell renderer, create a Flash document with a list-based component. You must also
create an empty movie clip and link it to the ActionScript 2.0 class MultiLineCell. Then, set the
cellRenderer property of the component to the linkage identifier of the movie clip. For
example, if you use a DataGrid component with the instance name
grid and a movie clip with
the linkage identifier
MultiLineCell, the following code would cause the first column of the grid
to render with multiline text:
grid.getColumnAt(0).cellRenderer = "MultiLineCell";
Note: Remember to add data to the DataGrid component.
If you were using a ComboBox component, you could write the following code:
comboBox.dropdown.cellRenderer = "MultiLineCell"
The following is the code for the MultiLineCell.as file:
class MultiLineCell extends mx.core.UIComponent
{
var multiLineLabel; //the label to be used for text
var owner; // the row that contains this cell
var listOwner; // the List/grid/tree that contains this cell
// empty constructor
function MultiLineCell()
{
}
// UIObject expects you to fill in createChildren by instantiating
// all the movie clip assets you might need upon initialization.
// Here, it's just a label.
function createChildren():Void
{
// createLabel is a useful method of UIObject--all components use this