1120:访问未定义的属性 [英] 1120: Access of undefined property

查看:47
本文介绍了1120:访问未定义的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我在 arrMonth.push 行出现 1120: Access of undefined property arrMonth. 错误以及如何更正?

Why I'm getting a 1120: Access of undefined property arrMonth. error at the line arrMonth.push and how to correct it?

<fx:Script>
    <![CDATA[
        [Bindable]
        public var arrMonth:Array = new Array();

        arrMonth.push({label: "January"});
    ]]>
</fx:Script>

推荐答案

该错误的原因是您的逻辑(push 语句)不在方法内部,因此被认为是在类级别(即静态)而不是在实例级别.

The reason for that error is that your logic (the push statement) is not inside a method, hence it is considered to be at class level (i.e. static) instead of at the instance level.

这意味着有两种修复方法:

1/也将变量设为静态(我怀疑这不是您想要的,但它会修复错误).

1/ Make the variable static too (I suspect this is not what you want, but it will fix the error).

<fx:Script>
<![CDATA[
    public static var arrMonth:Array = new Array();

    arrMonth.push({label: "January"});
]]>
</fx:Script>

2/把逻辑放在一个方法中,例如:

2/ Put the logic in a method, for instance:

<fx:Script>
<![CDATA[
    [Bindable]
    public var arrMonth:Array = new Array();

    override protected function initializationComplete():void {
        super.initializationComplete();
        arrMonth.push({label: "January"});
    }
]]>
</fx:Script>

这篇关于1120:访问未定义的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆