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
•
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
property of the component to the linkage identifier of the movie clip. For
cellRenderer
example, if you use a DataGrid component with the instance name
the linkage identifier
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
, the following code would cause the first column of the grid
MultiLineCell
instead.
size()
and a movie clip with
grid
CellRenderer API
147
Need help?
Do you have a question about the FLASH MX 2004-USING COMPONENTS and is the answer not in the manual?