1120: Access of undefined property

二次信任 提交于 2019-12-11 10:52:31

问题


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>

回答1:


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.

Which means there are two ways to fix it:

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/ 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>


来源:https://stackoverflow.com/questions/11922591/1120-access-of-undefined-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!