dimanche 18 septembre 2016

How to get column width inside AS3 DataGrid CellRenderer?

I have a DataGrid with one column showing picture icon(s). This is done by using a special CellRenderer. Is it possible to find column width inside the CellRenderer? this.width always returns a number that is obviously wrong (152), no matter what the actual column width is. I tried this on PC and on Android.

I need to know the column width to center the picture. It would be probably possible to pass the actual column width to the CellRenderer using a static variable, but I wonder if I'm overlooking something obvious.

public class CustomImageCellRenderer extends CellRenderer 

    public function CustomImageCellRenderer()

        var iconClass : Class = getDefinitionByName("icon") as Class;
        var iconMC : MovieClip = new iconClass();

        trace("width=" + width); // always returns 152

        addChild(iconMC );      


    override protected function drawBackground():void
        var skin : Object;

        if (_listData.index % 2 == 0)
            skin = CellRenderer_upSkin2;
        } else {
            skin = CellRenderer_upSkin;         

        setStyle("upSkin", skin);   
        setStyle("overSkin", skin); 
        setStyle("downSkin", skin); 

        setStyle("selectedOverSkin", skin); 
        setStyle("selectedDownSkin", skin);  
        setStyle("selectedUpSkin", skin);




Aucun commentaire:

Enregistrer un commentaire