Skip to main content
Inspiring
January 4, 2010
Answered

Custom CellRenderer?

  • January 4, 2010
  • 1 reply
  • 1458 views

I have attempted to implement a custom cellrenderer for my list component in AS3 in Flash CS3.

Here is what I have in the FLA.

import flash.display.MovieClip;
import fl.controls.List;

stop();

var cr:customRenderer = new customRenderer();

lstTest.setStyle("cellRenderer", cr);

lstTest.addItem({label:"Jeff"});

lstTest.addItem({label:"Ben"})

Where lstTest if the instance of the list component on the stage.

Here is my customRenderer class;

package

{

    import fl.controls.listClasses.CellRenderer;

    import flash.text.TextFormat;

    public class customRenderer extends CellRenderer

    {       

        public function customRenderer()

        {

            var newFormat:TextFormat = new TextFormat("Arial", 12, 0x00FF00);

                setStyle("textFormat", newFormat);

        }

    }

}

When the custom renderer is applied to the list component the only cell that is rendered witht he new new font and color is the last one added to the component. The other one doesn't show up at all. If I click on the cell showing I get and error from the list component.

Can anyone see what I am doing wrong with this custom cellrenderer?

This topic has been closed for replies.
Correct answer kglad

use:


stop();

lstTest.setStyle("cellRenderer", customRenderer);

lstTest.addItem({label:"Jeff"});

lstTest.addItem({label:"Ben"})


1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
January 4, 2010

use:


stop();

lstTest.setStyle("cellRenderer", customRenderer);

lstTest.addItem({label:"Jeff"});

lstTest.addItem({label:"Ben"})


MaxManNHAuthor
Inspiring
January 4, 2010

That did it!

And after seeing what you said I realize that creating a single instance of the cellRenderer and then attempting to use it across all the cells in the list component was a little stupid of me.

kglad
Community Expert
Community Expert
January 4, 2010

you're welcome.