有变数问题

时间:2013-09-27 14:24:17

标签: actionscript-3 variables flash-cs5

我在更新变量时遇到问题。下面,我的主文档功能的级别等于1并生成多个图块。它确实等于1,但如果var等于true,我会将if语句说成一个级别。

    public var enemiesDefeated:Boolean = false;        
    addChild(level);
    //START THE GAME AT LEVEL 1//
    level.levelNumber = 1;
    if (enemiesDefeated == true){
        level.levelNumber += 1;
    }
    var tileh:int = 60;

    for (var Y:int=0; Y<floor.length; Y++)
    {
        for (var X:int=0; X<floor[Y].length; X++)
        {
                var cell:MovieClip = new Tile(X,Y);
            cell.gotoAndStop(floor[Y][X]);
            cell.x = ((X-Y)*tileh)+365;
            cell.y = ((X+Y)*tileh/2)+70;
            addChild(cell);

            cell.addEventListener(MouseEvent.CLICK, mouseclick);
            cell.addEventListener(Event.ENTER_FRAME, onGame);
            cell.addEventListener(Event.ADDED_TO_STAGE, addEnemy);
        }
    }

如果我消灭所有敌人,变量enemiesDefeated在我的onGame函数中变为true,但是,在敌人击败等于true之后,等级保持在等级1。

function onGame(event:Event){

    ...

    if (enemy.enemyHP <= 0) 
        {
             removeChild(enemy);
             enemy.enemyDead = true;
             enemiesDefeated = true;
             trace("Dead", enemy.enemyDead);
        }
}

有没有办法解决这个问题?

0 个答案:

没有答案