Flex 4.5 Mobile 中的自定义着色错误
当值 < 时,我尝试将数据着色为红色。 0,否则为绿色。我用来显示列,我的 itemRenderer 操作脚本文件给出错误“无法访问 null
对象的属性”。在我的 as 文件中,当我调试时,我可以看到“data”的值变量为 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]
I am trying to colour data red when the value < 0, otherwise green. I am using to display columns and my itemRenderer actions script file gives me error "cannot access property of a null
object,. In my as file, when I debug, I can see the value of "data" variable as null
and as soon as it calls the super constructor it gives this error.
My action script file
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);
}
}
My call from the mxml file is :
<s:GridColumn id="name1" dataField="name" headerText="Name" />
<s:GridColumn dataField="excess_return" headerText="Excess Return" itemRenderer="util.ConditionalColoredLabelAS"/>
Error is
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]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
终于找到答案
了
函数是
声明是
Finally found the answer
The
function is
The declarations are