我试图在值 < 0 时将数据着色为红色,否则为绿色。我用来显示列,我的 itemRenderer 操作脚本文件给了我错误“无法访问null
对象的属性,。在我的 as 文件中,当我调试时,我可以在null
它调用时看到“数据”变量的值它给出了这个错误的超级构造函数。
我的动作脚本文件
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);
}
}
我从 mxml 文件中调用的是:
<s:GridColumn id="name1" dataField="name" headerText="Name" />
<s:GridColumn dataField="excess_return" headerText="Excess Return" itemRenderer="util.ConditionalColoredLabelAS"/>
错误是
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at spark.components::Group/addElement()[E:\dev\4.5.1\frameworks\projects\spark\src\spark\components\Group.as:1342]
at spark.components.gridClasses::GridLayout/createTypicalItemRenderer()[E:\dev\4.5.1\frameworks\projects\spark\src\spark\components\gridClasses\GridLayout.as:748]
at spark.components.gridClasses::GridLayout/updateTypicalCellSizes()[E:\dev\4.5.1\frameworks\projects\spark\src\spark\components\gridClasses\GridLayout.as:883]
at spark.components.gridClasses::GridLayout/measure()[E:\dev\4.5.1\frameworks\projects\spark\src\spark\components\gridClasses\GridLayout.as:444]
at spark.components.supportClasses::GroupBase/measure()[E:\dev\4.5.1\frameworks\projects\spark\src\spark\components\supportClasses\GroupBase.as:1148]
at mx.core::UIComponent/measureSizes()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\core\UIComponent.as:8496]
at mx.core::UIComponent/validateSize()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\core\UIComponent.as:8420]
at spark.components::Group/validateSize()[E:\dev\4.5.1\frameworks\projects\spark\src\spark\components\Group.as:1012]
at mx.managers::LayoutManager/validateClient()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\managers\LayoutManager.as:987]
at mx.core::UIComponent/validateNow()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\core\UIComponent.as:8067]
at spark.components::ViewNavigator/commitNavigatorAction()[E:\dev\4.5.1\frameworks\projects\mobilecomponents\src\spark\components\ViewNavigator.as:1878]
at spark.components::ViewNavigator/commitProperties()[E:\dev\4.5.1\frameworks\projects\mobilecomponents\src\spark\components\ViewNavigator.as:1236]
at mx.core::UIComponent/validateProperties()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\core\UIComponent.as:8209]
at mx.managers::LayoutManager/validateProperties()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\managers\LayoutManager.as:597]
at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\managers\LayoutManager.as:783]
at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\managers\LayoutManager.as:1180]