繁体   English   中英

语法错误:错误#1009:无法访问空对象引用的属性或方法

[英]SyntaxError: Error #1009: Cannot access a property or method of a null object reference

在Adobe Flash CC中测试游戏时,出现以下错误: TypeError: Error #1009: Cannot access a property or method of a null object reference.

这基本上是围绕该错误的代码(我删除了不重要的部分以使其更清楚):

package ui.levelSelect {
    import flash.display.MovieClip;

    public class LevelsContainer extends MovieClip {

        public var levelThumbs:Array;
        public var levels:Array = [{name:'level1'},{name:'level2'}];

        public function LevelsContainer(){

            for(var i:String in levels) {
                var index:int = int(index);

                levelThumbs[index] = new MovieClip; //This is the line where I get the error

            }

        }



    }

}

是什么导致此错误? levelThumbs已经声明正确了吗? 将其更改为this.levelThumbs也不起作用...

简单声明变量不会为该对象分配任何内存,因此其值为null。 您实际上必须通过调用new Array[]levelThumbs数组分配内存。

public var levelThumbs:Array = new Array;

要么

public var levelThumbs:Array = [];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM