AS3无法访问多维数组的子节点

时间:2016-03-19 10:15:30

标签: arrays actionscript-3 flash multidimensional-array

下面是创建多维tableCardsOfPlayers数组的代码示例,其中包含座位名称的键(如“firstSeat”,“secondSeat”等)。那些键应该包含一个“card1”=>的数组。卡片()参考:

using namespace std;

但是当我访问

var players:Array = lastJoinedRoom.userList;
var cardsArray:Array = ["card1", "card2", "card3", "card4", "card5"];
tableCardsOfPlayers = new Array();
for each(var userTemp:User in players)
{
    var userVars:Array = userTemp.getVariables();
    var userVarDic:Array = new Array();
    var seat:String = userTemp.getVariable("seat").getStringValue();
    if(tableCardsOfPlayers[seat] == undefined) tableCardsOfPlayers[seat] = [];

    for each(var userVar:UserVariable in userVars)
    {
        if (cardsArray.indexOf(userVar.name) != -1)
        {
            tableCardsOfPlayers[seat][userVar.name] = new Card();
        }
    }

}   

AS3调试器抛出异常

 trace(tableCardsOfPlayers["firstSeat"]["card1"]);

我做错了什么?我在这里搜索过类似的问题,检查每一行,一切似乎都很好。

tableCardsOfPlayers的递归跟踪结果

"TypeError: Error #1009: Cannot access a property or method of a null object reference."; 

Debug picture

递归跟踪功能:

--- secondSeat :    
------ card2 : [object Card]   
------ card4 : [object Card]   
------ card3 : [object Card]   
------ card5 : [object Card]   
------ card1 : [object Card]   
--- firstSeat :    
------ card2 : [object Card]   
------ card4 : [object Card]   
------ card3 : [object Card]   
------ card5 : [object Card]   
------ card1 : [object Card] 

0 个答案:

没有答案