0

我的一段代码有问题,它似乎在下面的这个类中:

package 
{

import flash.display.MovieClip;
//levels are 11x9

public class Level extends MovieClip
{

    var level1:Array=new Array(
    1,1,1,1,1,1,1,1,1,1,1,
    1,0,0,0,0,0,0,0,0,0,1,
    1,0,0,0,0,0,0,0,0,0,1,
    1,0,0,0,0,0,0,0,0,0,1,
    1,0,0,1,0,0,0,0,0,0,1,
    1,0,0,1,1,1,0,0,0,1,1,
    1,0,0,0,0,0,0,1,1,0,1,
    1,1,1,1,1,1,1,1,1,1,1);
    var grid:Array = new Array(11);
    public function Level()
    {
        for (var i = 0; i < 9; i++)
        {
            grid.push(new Array(9));
        }
        for (var xr=0; xr<11; xr++)
        {
            for (var yr=0; yr<9; yr++)
            {
                var type = level1[yr * 11 + xr];
                var obj:Wall = new Wall(xr*50,yr*50,type);
                grid[xr][yr] = obj;
                if (type!=0)
                {
                    addChild(obj);
                }
            }
        }

    }
}
}

现在我做了一些工作,错误是错误代码#1010:术语未定义并且没有属性。更具体地说,我做了一些调试并确定了确切的行是 grid[xr][yr]=obj; 任何帮助表示赞赏。在此处输入代码 在此处输入代码

4

1 回答 1

1

改变

grid.push(new Array(9));

grid[i]=new Array(9);

[编辑]

其实试试这个

var level1:Array=new Array(
1,1,1,1,1,1,1,1,1,1,1,
1,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,1,
1,0,0,1,0,0,0,0,0,0,1,
1,0,0,1,1,1,0,0,0,1,1,
1,0,0,0,0,0,0,1,1,0,1,
1,1,1,1,1,1,1,1,1,1,1);


var grid:Array = new Array(11);
public function Level()
{


   for(var row=0;col<11;row++){
     grid[col] = new Array(9);
     for(var col=0;col<9;col++){
        var type = level1[row* 11 + col];
        var obj:Wall = new Wall(col*50,row*50,type);
        grid[col][row] = obj;
        if (type!=0){
           addChild(obj);
        }
     }
  }
}
于 2013-07-17T21:49:39.990 回答