flex 4.5 Mobile中的自定义着色错误

时间:2011-07-05 18:55:44

标签: mobile itemrenderer flex4.5

我正在尝试在数据值为<时将数据着色为红色。 0,否则为绿色。我用来显示列和我的itemRenderer操作脚本文件给我错误“无法访问null对象的属性,在我的as文件中,当我调试时,我可以看到”data“变量的值为{ {1}}并且一旦调用超级构造函数就会出现此错误。

我的动作脚本文件

null

来自mxml文件的调用是:

                             

public class ConditionalColoredLabelAS extends LabelItemRenderer 
{
    public function ConditionalColoredLabelAS() {
        if (data !=null)
        super();

    }

    // Use the value of the myColor property to draw 
    // the background color of the item in the list. 
    override protected function drawBackground(unscaledWidth:Number, unscaledHeight:Number):void {
        // Define a var to hold the color.
        var myColor:uint;
        if (data !=null)
        {
            // Determine the RGB color value from the label property.
        if (data == "red")
            myColor = 0xFF0000;
        if (data == "green")
            myColor = 0x00FF00;
        if (data == "blue")
            myColor = 0x0000FF;
        }
        //graphics.beginFill(myColor, 1);
        //graphics.drawRect(0, 0, unscaledWidth, unscaledHeight); 

    }
}

错误是

                <s:GridColumn id="name1" dataField="name" headerText="Name" />
                <s:GridColumn dataField="excess_return" headerText="Excess Return" itemRenderer="util.ConditionalColoredLabelAS"/>

1 个答案:

答案 0 :(得分:0)

终于找到了答案

在 功能是

private function returnItemRenderer( item: Object, column: GridColumn ): IFactory       

        {   
            if (item == null)
                return default_grid_item_renderer;

            //var field:String = column.dataField;
            if(item._return < 0)
                return red_grid_item_renderer;
            else if (item._return>0)
                return green_grid_item_renderer;
            return default_grid_item_renderer;  
            //return new ClassFactory( DefaultGridItemRenderer );         
        }   
    ]]>
</fx:Script>

声明是

<fx:Declarations> 
     <fx:Component id="default_grid_item_renderer" > 
         <s:DefaultGridItemRenderer /> 
     </fx:Component>
     <fx:Component id="red_grid_item_renderer" >
         <s:DefaultGridItemRenderer color="0xFF0000"/> 
     </fx:Component>
     <fx:Component id="green_grid_item_renderer" > 
         <s:DefaultGridItemRenderer color="0x00FF00"/>
    </fx:Component>
</fx:Declarations>

<s:DataGrid id="top5Grid" width="100%" height="100%"
                    dataProvider="{getDataResultMax.lastResult}">
            <s:columns>
                <s:ArrayList>

                    <s:GridColumn dataField="impact" headerText="Impact" itemRendererFunction="impactItemRenderer"/>
                    <s:GridColumn dataField="_return" headerText="Return" itemRendererFunction="returnItemRenderer"/>
                </s:ArrayList>      
            </s:columns>
        </s:DataGrid>