使SelectionColor在mx:datagrid中透明

时间:2012-07-31 08:48:44

标签: actionscript-3 flash flex flex3

我在我的flex应用程序中使用mx:DataGrid组件。我展示了这样的网格:

enter image description here

我想将选定的蓝色更改为透明。我使用以下代码:

<mx:DataGrid id="dg" dataProvider="{arrDg}" width="100%" height="100%" 
    draggableColumns="false" rowCount="{arrDg.length}" click="dgClickHandler(event)" 
    variableRowHeight="true" resizableColumns="false" sortableColumns="false" 
    selectionColor="#00000000" verticalScrollPolicy="off">

但这会将颜色改为黑色而不是透明。

请帮忙。

2 个答案:

答案 0 :(得分:1)

<强> [编辑[

哎呀,没注意到那个颜色有8个零。 Flash不支持RGBA(或具有alpha /透明度的颜色值)。

[结束编辑]

如果您不想在选择时显示任何突出显示,请尝试将(mx)DataGrid的{​​{3}}属性设置为false。看来你有一个点击处理程序,关闭选择可能会阻止你的点击处理程序做它的工作:(

如果您确实需要某种选择指示器,但是想要修改选择颜色的alpha(透明度),则该样式设置不存在(即:没有“selectionAlpha”样式)。您必须创建一个自定义数据网格类来执行此操作。

答案 1 :(得分:0)

如果您需要mx:DataGrid可选择但又希望选择颜色不影响单元格/行的颜色,则可以使用此方法:

扩展DataGrid覆盖函数drawSelectionIndicator并将函数内容保留为空(您可能也有兴趣覆盖drawHighlightIndicator函数)

public class CustomRowColorDataGrid extends DataGrid
{
    public function CustomRowColorDataGrid()
    {
        super();
    }

    override protected function drawSelectionIndicator(indicator:Sprite, x:Number, y:Number, w:Number, h:Number, color:uint, itemRenderer:IListItemRenderer):void
    {
        //If you want a rectangle arround the selected row use call this method 
        //Rectangle(indicator,x,y,0xFF9900, 2,h) ;
    }

    override protected function drawHighlightIndicator(indicator:Sprite, x:Number, y:Number, w:Number, h:Number, color:uint, itemRenderer:IListItemRenderer):void
    {
        Rectangle(indicator,x,y,highlight, 2,h) ;
    }

    private function Rectangle(indicator:Sprite, xx:int, yy:int,colorBorde:uint,grosor:int, h:int):void
    {
        var g:Graphics ;
        var w:int ;

        w = this.width - this.verticalScrollBar.width-1 ;

        g = Sprite(indicator).graphics;
        g.clear();
        g.lineStyle(grosor,colorBorde) ;
        g.drawRect(0,1,w-grosor,h-grosor) ;

        indicator.x = xx;
        indicator.y = yy;
    }       
}
相关问题