setComponentStyle doesn't work in AS3

152 Views Asked by At

I have a list component in the main timeline of my movie and...

var tf:TextFormat = new TextFormat();
tf.color = xmlData.config.playList.@textColor;
StyleManager.setStyle("textFormat", tf);

the code above works fine but why doesn't this work?

StyleManager.setComponentStyle(List, "textFormat", tf);
1

There are 1 best solutions below

4
helloflash On

The CellRenderer class is adapted.

The CellRenderer class defines methods and properties for list-based components to use to manipulate and display custom cell content in each of their rows. A customized cell can contain text, an existing component such as a CheckBox, or any class that you create. The list-based components that use this class include the List, DataGrid, TileList, and ComboBox components.

CustomCellRenderer.as

You have first created a class named CustomCellRenderer (File > New > ActionSript File).

package com 
{
    import fl.controls.listClasses.CellRenderer;
    import flash.text.TextFormat;

    public class CustomCellRenderer extends CellRenderer
    {
        public function CustomCellRenderer()
        {
            setStyle("textFormat", new TextFormat("arial", 10, 0xFF00FF));
        }
    }
}

myFla.fla

If you want to apply your textFormat to the instance myList of the class List:

import com.CustomCellRenderer;

myList.setStyle("cellRenderer", CustomCellRenderer);

If you want to apply your textFormat to all the instances of the class List:

import com.CustomCellRenderer;
import fl.managers.StyleManager;

StyleManager.setComponentStyle(List, "cellRenderer", CustomCellRenderer);

Adobe help about CellRenderer.