AS3:如何使用if语句检查变量?

时间:2015-04-28 16:45:04

标签: actionscript-3 flash

所以这段代码似乎应该顺利运行给我但我似乎无法使用if语句来检查分数然后使按钮出现。有什么建议吗?

//Score variable
var score = 0;

//Multiplier variable
var multiplier = 1;

//Point Scorer
function PointScore() {
score = score + multiplier;
}

//update score function
function updateScore() {
txtPlayerScore.text = "Smash Points: " + score;
}

//Score Text
txtPlayerScore.text = "Smash Points: " + score;

//Make Power Up button invis
btnPowerUp.visible = false;

//If the score is 50 the button is now visible
if (score == 50){
btnPowerUp.visible = true;
}

//Power Up button
btnPowerUp.addEventListener(MouseEvent.MOUSE_DOWN, UpClicked);

function UpClicked (e:MouseEvent){
multiplier = 5;
}

1 个答案:

答案 0 :(得分:2)

根据您发布的代码,if检查毫无意义,因为它在您将分数设置为0后立即发生。您希望每次更改时检查分数,例如将其放入PointScore()函数中。此外,您可能希望if(score >= 50)代替== 50,否则如果分数超过50则不会触发条件。

function PointScore() {
    score = score + multiplier;
    checkScore();
}

function checkScore(){
    if(score >= 50){
        btnPowerUp.visible = true;
    }
}