I hate that Cellrenderer!

No i dont, but its really anoying!:{

I’ve made a cellrenderer that should show a Backgroundcolor for each item, depending on the value. - this way i have an easy color list. It works, but if i scroll there are some rows that does not get shown and the same is true if i insert a new row.

PLEASE HELP!!!:crying:

This is my cellrenderer: (used macromedia template)


class ColorCell extends mx.core.UIComponent
{
    private var colorLabel;     // The label to be used for text.
    private var owner;            // The row that contains this cell.
    private var listOwner;        // The List/grid/tree that contains this cell.
    
    // Cell height offset from the row height total and preferred cell width.
    private static var PREFERRED_HEIGHT_OFFSET = 4;
    private static var PREFERRED_WIDTH = 100;
    // Starting depth.
    private var startDepth:Number = 1;

    // Constructor.  Should be empty.
    public function ColorCell()
    {
    }

    /* UIObject expects you to fill in createChildren by instantiating
    all the movie clip assets you might need upon initialization. 
    In this case we are creating one label*/
    public function createChildren():Void
    {
        // The createLabel method is a useful method of UIObject and a handy way to make labels in components.
        var c = colorLabel = this.createLabel("colorLabel", startDepth);
        // Links the style of the label to the style of the grid
        c.styleName = listOwner;
        c.selectable = false;
        c.tabEnabled = false;
        c.background = true;
        c.border = false;
        c.multiline = false;
        c.wordWrap = false;
    }

    public function size():Void
    {
        /* By extending UIComponent, which imports UIObject, you get setSize for free,
        however, UIComponent expects you to implement size().
        Assume __width and __height are set for you now.
        You're going to expand the cell to fit the whole rowHeight.
        The rowHeight itself is a property of the list type component that we are rendering a cell in.
        Since we want the rowHeight to fit two lines, when creating the list type component using this
        cellRenderer class, make sure its rowHeight property is set large enough that two lines of text
        can render within it.*/
    
        /*__width and __height are the underlying variables 
        of the getter/setters .width and .height.*/
        var c = colorLabel;
        c.setSize(__width, __height);
    }

    // Provides the preferred height of the cell.  Inherited method.
    public function getPreferredHeight():Number
    {
        /* The cell is given a property, "owner",
        that references the row. It’s always preferred
        that the cell take up most of the row's height.
        In this case we will keep the cell slightly smaller.*/
        return owner.__height - PREFERRED_HEIGHT_OFFSET;
    }

    // Called by the owner to set the value in the cell.  Inherited method.
    public function setValue(suggestedValue:String, item:Object, selected:Boolean):Void
    {
        /* If item is undefined, nothing should be rendered in the cell, 
        so set the label as invisible. Note: For scrolling List type components
        like a scrolling datagrid, the cells are intended to be empty as they scroll
        just out of sight, and then the cell is reused again and set to a new value 
        producing an animated effect of scrolling.  For this reason, you cannot rely on
        any one cell always having data to show or the same value.*/
        if (item==undefined){
            colorLabel._visible = false;//text.
        }
        //colorLabel.text = suggestedValue;
        if(suggestedValue != undefined && suggestedValue != "")
           colorLabel.backgroundColor = suggestedValue;//setStyle("backgroundColor",suggestedValue);
        else
             colorLabel.backgroundColor = 0x999999;//_visible
    }
    // function getPreferredWidth :: only for menus and DataGrid headers
    // function getCellIndex :: not used in this cell renderer
    // function getDataLabel :: not used in this cell renderer
}