【问题标题】:mxml null referencemxml 空引用
【发布时间】:2012-09-28 10:24:45
【问题描述】:

我有一个示例自定义 mxml 组件 CustomRadio

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:RadioButton id="radio" />
    <mx:Script>
        public override function set label(value:String):void { 
            this.radio.label = value;
        }
        public override function get label():String {
            return this.radio.label;
        }
    </mx:Script>
</mx:VBox>

和一个应用程序

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"  xmlns:local="*">
    <local:CustomRadio  label="xxx" />
</mx:WindowedApplication>

我在设置标签中得到空引用错误,说 this.radio 为空。为什么?

【问题讨论】:

    标签: apache-flex mxml


    【解决方案1】:

    RadioButton 标记需要包含 Script 标记。你现在拥有它的方式,脚本标签只是 VBox 的一部分。由于您使用的是“this”指针,因此它指的是 VBox。

    【讨论】:

    • 如果在使用值之前在“set”函数中设置断点(在其中放置跟踪或类似内容) - 单选按钮的任何部分是否在“this”指针中定义?
    • 试试这个:cookbooks.adobe.com/post_Button_with_html_text-14186.html -> 看起来你需要 'super' 而不是 'this'
    猜你喜欢
    • 1970-01-01
    • 2010-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-11
    • 1970-01-01
    相关资源
    最近更新 更多