2号线? 1046:未找到类型或不是编译时常量:屏蔽

时间:2014-07-16 20:45:31

标签: actionscript-3

1046:未找到类型或不是编译时常量:屏蔽。 我试图制作射击游戏,但这个错误不断涌现。它说错误是第2行,但第2行没有任何内容!我不明白!

包{

import flash.display.MovieClip;
import flash.events.Event;
import flash.ui.Keyboard;

public class Ship extends MovieClip{

    var velocity:Number;
    var shootLimiter:Number;
    var health:Number;
    var maxHealth:Number; 

        function Ship(){

        velocity = 10;
        shootLimiter = 0;
        health = 100;
        maxHealth = 100;
        addEventListener("enterFrame", move);

    }

    function kill(){

        var explosion = new Explosion();
        stage.addChild(explosion);
        explosion.x = this.x;
        explosion.y = this.y;

        removeEventListener("enterFrame", move);
        this.visible = false;

        Game.gameOver();

    }

    function takeDamage(d){

        health -= d;

        if(health<=0){
            health = 0;
            kill();
        }

        Game.healthMeter.bar.scaleX = health/maxHealth;

    }

    function move(e:Event){

        shootLimiter += 1;

        if(Key.isDown(Keyboard.D)){
            this.x = this.x + velocity;
        }
        if(Key.isDown(Keyboard.A)){
            this.x = this.x - velocity;
        }
        if(Key.isDown(Keyboard.W)){
            this.y = this.y - velocity;
        }
        if(Key.isDown(Keyboard.S)){
            this.y = this.y + velocity;
        }
        if(Key.isDown(Keyboard.SPACE) && shootLimiter > 8){
            shootLimiter = 0;
            var b = new Bullet();
            stage.addChild(b);
            b.x = this.x + 50;
            b.y = this.y + 3;
        }

        if(shield.visible == true){
            shield.alpha -= 0.0005;
            if(shield.alpha == 0){
                shield.visible = false;
                shield.alpha = 1;
            }
        }

    } 

}

}

1 个答案:

答案 0 :(得分:0)

下面:

    if(shield.visible == true){
        shield.alpha -= 0.0005;
        if(shield.alpha == 0){
            shield.visible = false;
            shield.alpha = 1;
        }
    }

您正在使用变量'shield'而不声明/实例化它。这不是我期望看到的这个问题的错误信息,但这是一个问题 “船”是否支持扩展具有“盾牌”属性的东西?你是从另一个来源复制而忘了包含它吗?您提供的代码是否不完整? (只是可能导致这种情况的几种情况。)
无论如何,你需要解决这个问题。