数字在AS3中不像数字

时间:2014-12-19 23:10:36

标签: actionscript-3 variables numbers

这是我的代码:

function castBurn()
{
    var cardNumber = currentCard;// == 149 (currentCard:int)
    var card1 = cardNumber - 1;// 149 - 1 = 148
    var card2 = cardNumber + 1;// 149 +1 = 150
    var card3 = cardNumber - row;// row = 23 and so on
    var card4 = cardNumber + row;

    //cardArray:Array (full of objects(Cards)
    cardArray[card1].burn = true;// card1 is recognized and flips
    cardArray[card2].burn = true;// throws a runtime error (term is unidentified)
    cardArray[card3].burn = true;// See bottom for notes
    cardArray[card4].burn = true;

    for (var j = 0; j < cardArray.length; j++)
    {// This works 
        var card = cardArray[j];
        if (card.burn == true)
        {
            if (card.wall != true)
            {
                card.flip.gotoAndPlay(2);
            }
        }
    }
}

如果我将card1,card2,card3,card4变量本身替换为数字,那么效果很好。但是我需要根据“当前卡片”来计算这些数字......之前我已经做了好几次了。我错过了什么?...我也尝试写var card1 = cardArray[currentCard + 1];但这种方法也不起作用。我开始工作的唯一方法是写card1 = 148;

1 个答案:

答案 0 :(得分:0)

AS3是强类型语言。在代码中使用Type声明,编译器会告诉你出了什么问题。