Actionscript 3 操作脚本3.0公共属性只能在包内使用

Actionscript 3 操作脚本3.0公共属性只能在包内使用,actionscript-3,Actionscript 3,下面的代码位于名为Script_1.as的文件中 package{ import flash.display.MovieClip; import flash.events.Event; import flash.events.MouseEvent; import flash.display.*; import flash.events.*; import flash.geom.Rectangle; import flash.media.Sound; import flash.text.*; pu

下面的代码位于名为Script_1.as的文件中

package{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.*;
import flash.events.*;
import flash.geom.Rectangle;
import flash.media.Sound;
import flash.text.*;
public class Game extends flash.display.MovieClip{
    public static const STATE_INIT:int = 10;
    public static const STATE_PLAY:int = 20;
    public static const STATE_END_GAME:int = 30;
    public var gameState:int = 0;
    public var score:int = 0;
    public var chances:int = 5;
    public var bg:MovieClip;
    public var enemies:Array;
    public var paly:MovieClip;
    public var level:Number = 0;
    public var scoreLable:TextField = newTextField
    public var levelLable:TextField = newTextField
    public var chancesLable:TextField = newTextField
    public var scoreText:TextField = newTextField
    public var levelText:TextField = newTextField
    public var chancesText:TextField = newTextField
    public const SCOREBOARD_Y:Number = 380
    public function Game(){
        addEventListener(Event.ENTER_FRAME, gameLoop);
        bg = new BackImage();
        addChild(bg);
        scoreLable.text = "Score:";
        levelLable.text = "level:";
        chancesLable.text = "Misses:";
        scoreText.text = "0";
        levelText.text = "1";
        chancesText.text = "5";
        scoreLable.y = SCOREBOARD_Y;
        levelLablel.y = SCOREBOARD_Y;
        chancesLabel.y = SCOREBOARD_;
        scoreText.y = SCOREBOARD_Y;
        levelText.y = SCOREBOARD_Y;
        chancesText.y = SCOREBOARD_Y;
        scoreLabel.x = 5;
        scoreText.x = 50;
        chancesLabel.x = 105;
        chancesText.x = 155;
        levelLabel.x = 205;
        levelText.x = 260
        addChild(scoreLabel);
        addChild(levelLabel);
        addChild(chancesLabel);
        addChild(scoreText);
        addChild(levelText);
        addChild(chancesText);
        gameState = STATE_INIT;
    }
        public function gameLoop(e:Event):void{
        switch(gameState){
            case STATE_INIT:
                initGame();
                break;
            case STATE_PLAY:
                playGame();
                break;
            case STATE_END_GAME:
                endGame();
                break;
        }
        //public function initGame():void{
            score = 0;
            chances = 5;
            player = new playerImage();
            enemies = newArray();
            level = 1;
            levelText.text = leveltoString();
            addChild(player);
            player.startDrag(true,newRectangle(0,0,550,400))
            gameState = STATE_PLAY
        }
        //public function playGame():void{
            player.rotation += 15;
            makeEnemies();
            moveEnemies();
            testCollisions();
            testForEnd();
        }
        //public function makeEnemies():void{
            var chance:Number = Math.floor(Math.random()*100);
            var tempEnemy:MovieClip;
            if (chance < 2 + level) {
                tempEnemy = new EnemyImage()
                tempEnemy.speed = 3 + level;
                tempEnemy.gotoAndStop(Math.floor(Math.randome()*5)+1);
                tempEnemy.y = 435;
                tempEnemy.x = Math.floor(Math.randome()*515)
                addChild(tempEnemy);
                enemies.push(tempEnemy);
            }
        }
        //public function moveEnemies():void{
            /var tempEnemy:MovieClip;
            for (var i:int = enemies.length -1;i >= 0;i--){
                tempEnemy = enemies[i];
                tempEnemy.y -= tempEnemy.speed;
                if (tempEnemy.y < -35){
                    chances -= 1;
                    chancesText.text = chances.toString();
                    enemies.splice(i,1);
                    removeChild(tempEnemy);
                }
            }
        }
        public function testCollisions();void {
            var sound:Sound = new Pop();
            var tempEnemy:MovieClip;
            for (var i:int = enemies.length -1;i >= 0;i--){
                tempEnemy = enemies[i];
                if(tempEnemy.hitTestObject(player)){
                    score++;
                    scoreText.text = score.toString();
                    sound.play();
                    enemies.splice(i,1);
                    removeChild(tempEnemy);
                }
            }
        }
        public function testForEnd():void{
            if(chances == 5){
                gameState = STATE_END_GAME;
            }else if(score > level*20) {
                level++;
                levelText.text = level.toString();
            }
        }
        public function endGame():void{
            for(var i:int = 0; i< enemies.length; i++) {
                removeChild(enemies[i]);
            }
            enemies = [];
            player.stopDrag()
        }
    }
}
包{
导入flash.display.MovieClip;
导入flash.events.Event;
导入flash.events.MouseEvent;
导入flash.display.*;
导入flash.events.*;
导入flash.geom.Rectangle;
导入flash.media.Sound;
导入flash.text.*;
公共类游戏扩展flash.display.MovieClip{
公共静态const STATE_INIT:int=10;
公共静态const STATE_PLAY:int=20;
公共静态常量状态\u结束\u游戏:int=30;
公共变量博弈状态:int=0;
公共风险价值分数:int=0;
公共风险价值机会:int=5;
公共风险背景:MovieClip;
公敌:阵法;
公共场所:MovieClip;
公共变量级别:Number=0;
公共变量scoreLable:TextField=newTextField
公共变量levelable:TextField=newTextField
public var chancestable:TextField=newTextField
公共变量scoreText:TextField=newTextField
公共变量levelText:TextField=newTextField
public var chancesText:TextField=newTextField
公共施工记分牌:编号=380
公共功能游戏(){
addEventListener(Event.ENTER_FRAME,gameLoop);
bg=新的背景图像();
addChild(bg);
scoreLable.text=“分数:”;
levelLable.text=“level:”;
chancestable.text=“未命中:”;
scoreText.text=“0”;
levelText.text=“1”;
chancesText.text=“5”;
scoreLable.y=记分牌_y;
Levelablel.y=记分牌_y;
chancesLabel.y=记分牌;
scoreText.y=记分牌_y;
levelText.y=记分牌_y;
chancesText.y=记分牌_y;
scoreLabel.x=5;
scoreText.x=50;
chancesLabel.x=105;
chancesText.x=155;
levelLabel.x=205;
levelText.x=260
addChild(分数标签);
addChild(levelLabel);
addChild(chancesLabel);
addChild(scoreText);
addChild(levelText);
addChild(chancesText);
gameState=STATE_INIT;
}
公共功能gameLoop(e:事件):无效{
开关(游戏状态){
案例状态_INIT:
initGame();
打破
案例状态与播放:
游戏();
打破
案例状态\u结束\u游戏:
结束游戏();
打破
}
//公共函数initGame():void{
得分=0;
机会=5;
player=新玩家图像();
敌人=新数组();
级别=1;
levelText.text=leveltoString();
addChild(玩家);
player.startDrag(正确,新矩形(0,0550400))
游戏状态=游戏状态
}
//公共函数playGame():无效{
玩家轮换次数+=15;
制造敌人();
移动敌人();
testCollisions();
testForEnd();
}
//公共函数makefeeds():void{
var chance:Number=Math.floor(Math.random()*100);
敌人:电影唇;
如果(机会<2+级){
tempEneyImage=新的EnemyImage()
速度=3+级;
tempToAndStop(Math.floor(Math.randome()*5)+1);
tempy=435;
temp敌我.x=Math.floor(Math.randome()*515)
addChild(临时敌人);
敌人。推(敌人);
}
}
//公共函数:void{
/敌人:电影唇;
对于(变量i:int=0.length-1;i>=0;i--){
敌人=敌人[我];
tempEquire.y-=tempEquire.speed;
如果(时间y<-35){
机会-=1;
chancesText.text=chances.toString();
3.拼接(i,1);
removeChild(临时敌人);
}
}
}
公共函数testCollisions();void{
var-sound:sound=new-Pop();
敌人:电影唇;
对于(变量i:int=0.length-1;i>=0;i--){
敌人=敌人[我];
如果(临时敌人。命中测试对象(玩家)){
分数++;
scoreText.text=score.toString();
声音。播放();
3.拼接(i,1);
removeChild(临时敌人);
}
}
}
公共函数testForEnd():void{
如果(机会==5){
gameState=状态\结束\游戏;
}否则如果(分数>等级*20){
级别++;
levelText.text=level.toString();
}
}
公共函数endGame():void{
for(变量i:int=0;i<0.length;i++){
清除孩子(敌人[i]);
}
敌人=[];
player.stopDrag()
}
}
}
错误报告包括:

Public属性只能在包中使用

(我将//放在这些错误行之前进行标记。它们不在原始代码中。)

语法错误:在变量之前应为标识符

语法错误:分号前应为rightbrace


(我把/放在这些错误之前。它们在同一行,并且/也不在原始代码中。)

尝试将文件重命名为Game.as。 尝试在开关大小写后添加}以关闭函数gameLoop()

附言:
这真的是你的代码吗?Math.randome()?纽特斯菲尔德?newArray()?公共函数testCollisions();无效的(;void)

您的代码中的所有函数声明都被注释掉了,还是您试图在那里指定一个错误?如果它们被注释掉,则会出现大量与不匹配的
}
相关的错误。(仅供将来参考,请勿修改此处发布的代码。如果要指定特定行,请将该行粘贴到单独的代码中。)