Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 1120:访问未定义的属性(有8个错误)_Javascript_Actionscript 3_Flash_Actionscript_Flash Cc - Fatal编程技术网

Javascript 1120:访问未定义的属性(有8个错误)

Javascript 1120:访问未定义的属性(有8个错误),javascript,actionscript-3,flash,actionscript,flash-cc,Javascript,Actionscript 3,Flash,Actionscript,Flash Cc,我是一名大学生,目前正在AS3上做一个游戏项目 当我运行我的游戏时,我得到了8个关于“1120:未定义属性的访问…”的错误。我不知道我做错了什么,所以有人能帮我吗 这是我的代码(是的,我知道它很长): 包{ 导入flash.display.*; 导入flash.events.*; 导入flash.text.*; 导入flash.utils.getTimer; 公共类平台游戏扩展MovieClip{ //运动常数 静态常量重力:数字=.004; //屏幕常数 静态常数边界:数字=100; //对象

我是一名大学生,目前正在AS3上做一个游戏项目

当我运行我的游戏时,我得到了8个关于“1120:未定义属性的访问…”的错误。我不知道我做错了什么,所以有人能帮我吗

这是我的代码(是的,我知道它很长):

包{
导入flash.display.*;
导入flash.events.*;
导入flash.text.*;
导入flash.utils.getTimer;
公共类平台游戏扩展MovieClip{
//运动常数
静态常量重力:数字=.004;
//屏幕常数
静态常数边界:数字=100;
//对象数组
私有变量fixedObjects:数组;
私有对象:数组;
//英雄与敌人
私人英雄:客体;
私人敌人:阵列;
//游戏状态
私有变量playerObject:数组;
个人分数:int;
private var gameMode:String=“start”;
私人玩家生活:int;
private var lastTime:Number=0;
//开始比赛
公共函数startPlatformGamess(){
playerObjects=新数组();
游戏分数=0;
gameMode=“play”;
playerLives=3;
}
公共功能startGameLevel(){
createHero();
加法器();
检查级别();
此.addEventListener(事件.输入\u帧,gameLoop);
stage.addEventListener(键盘事件、按键向下、按键向下功能);
stage.addEventListener(KeyboardEvent.KEY\u UP,keyup函数);
gameMode=“play”;
addScore(0);
showlifes();
}
//创建英雄对象并设置所有属性
公共函数createHero(){
hero=新对象();
hero.mc=gamelevel.hero;
英雄。inAir=错误;
英雄方向=1;
hero.animstate=“stand”;
hero.walkAnimation=新阵列(2)
hero.animstep=0;
英雄。跳跃=错误;
hero.moveLeft=false;
hero.moveRight=错误;
英雄。跳跃速度=.8;
英雄。行走速度=.15;
宽度=20.0;
英雄,身高=40.0;
hero.startx=hero.mc.x;
hero.starty=hero.mc.y;
}
公共功能附录(){
敌人=新阵列();
变量i:int=1;
while(true){
如果(游戏等级[“敌人”+i]==null)中断;
var敌人=新对象();
敌方.mc=游戏级别[“敌方”+i];
敌方。dx=0.0;
敌方:dy=0.0;
敌人。inAir=假;
方向=1;
敌人。animstate=“站立”
敌方.walkAnimation=新阵列(2);
敌方.animstep=0;
敌人.跳跃=错误;
敌方:正确=正确;
敌人。左=假;
敌方.跳跃速度=1.0;
敌方步行速度=0.08;
宽度=30.0;
高度=30.0;
敌人。推(敌人);
i++;
}
}
公共功能检查级别(){
fixedObjects=新数组();
otherObject=新数组();

对于(var i:int=0;i您的代码充满了拼写错误。
ActionScript区分大小写,变量需要正确拼写

第103行:
otherObject=new Array();
更改为
otherObjects=new Array();

第108行:
var floorObjects:Object=new Object();
更改为
var floorObject:Object=new Object();


第124行:
if(gamemode!=“play”)
更改为
if(gamemode!=“play”)

只验证你的变量名:你有
其他对象
地板对象
游戏模式
。哦,我的上帝,太感谢你了!我从来没有意识到,我一直在浏览:(但谢谢你!)!
package  {
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;
    import flash.utils.getTimer;


    public class PlatformGamess extends MovieClip {
        // movement constants
        static const gravity:Number=.004;

        // screen constants
        static const edgeDistance:Number=100;

        // object arrays
        private var fixedObjects:Array;
        private var otherObjects:Array;

        // hero and enemies
        private var hero:Object;
        private var enemies:Array;

        // game state
        private var playerObjects:Array;
        private var gameScore:int;
        private var gameMode:String="start";
        private var playerLives:int;
        private var lastTime:Number=0;

        // start game
        public function startPlatformGamess(){
            playerObjects=new Array();
            gameScore=0;
            gameMode="play";
            playerLives=3;
        }

        public function startGameLevel(){

            createHero();
            addEnemies();

            examineLevel();

            this.addEventListener(Event.ENTER_FRAME,gameLoop);
            stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDownFunction);
            stage.addEventListener(KeyboardEvent.KEY_UP,keyUpFunction);

            gameMode="play";
            addScore(0);
            showLives();

        }

        // creates the hero object and sets all properties
        public function createHero() {
            hero=new Object();
            hero.mc=gamelevel.hero;
            hero.inAir=false;
            hero.direction=1;
            hero.animstate="stand";
            hero.walkAnimation=new Array(2)
            hero.animstep=0;
            hero.jump=false;
            hero.moveLeft=false;
            hero.moveRight=false;
            hero.jumpSpeed=.8;
            hero.walkSpeed=.15;
            hero.width=20.0;
            hero.height=40.0;
            hero.startx=hero.mc.x;
            hero.starty=hero.mc.y;
        }

        public function addEnemies() {
            enemies = new Array();
            var i:int=1;
            while (true) {
                if (gamelevel["enemy"+i]==null) break;
                var enemy=new Object();
                enemy.mc=gamelevel["enemy"+i];
                enemy.dx=0.0;
                enemy.dy=0.0;
                enemy.inAir=false;
                enemy.direction=1;
                enemy.animstate="stand"
                enemy.walkAnimation = new Array(2);
                enemy.animstep = 0;
                enemy.jump = false;
                enemy.moveRight = true;
                enemy.moveLeft = false;
                enemy.jumpSpeed = 1.0;
                enemy.walkSpeed = .08;
                enemy.width = 30.0;
                enemy.height = 30.0;
                enemies.push(enemy);
                i++;
            }
        }

        public function examineLevel(){
            fixedObjects=new Array();
            otherObject=new Array();
            for (var i:int=0;i<this.gamelevel.numChildren;i++) {
                var mc=this.gamelevel.getChildAt(i);

                if ((mc is Floor) || (mc is Wall)) {
                    var floorObjects:Object=new Object();
                    floorObject.mc=mc;
                    floorObject.leftside=mc.x;
                    floorObject.rightside=mc.x+mc.width;
                    floorObject.topside.mc.y;
                    floorObject.bottomside=mc.y+mc.height;
                    fixedObjects.push(floorObject);

                } else if ((mc is Treasure) || (mc is Key) ||
                                (mc is Door) || (mc is Chest)) {
                                    otherObjects.push(mc);
                }
            }
        }

        public function keyDownFunction(event:KeyboardEvent) {
            if (gamemode != "play") return; // don't move until in play mode

            if (event.keyCode==37){
                hero.moveLeft=true;
            } else if (event.keyCode==39) {
                hero.moveRight==true;
            } else if (event.keyCode==32){
                if (!hero.inAir){
                    hero.jump=true;
                }
            }
        }

        public function keyUpFunction(event:KeyboardEvent) {
            if (event.keyCode == 37) {
                hero.moveLeft = false;
            } else if (event.keyCode == 39) {
                hero.moveRight = false;
            }
        }

        public function gameLoop(event:Event) {     
            if (lastTime==0)lastTime=getTimer();
            var timeDiff:int=getTimer()-lastTime;
            lastTime+=timeDiff;

            if (gameMode=="play"){
                moveCharacter(hero,timeDiff);
                moveEnemies(timeDiff);
                checkCollisions();
                scrollWithHero();
            }
        }


        // loop through all enemies and move them
        public function moveEnemies(timeDiff:int) {
            for(var i:int=0;i<enemies.length;i++) {

                // move
                moveCharacter(enemies[i],timeDiff);

                // if hit a wall, turn around
                if (enemies[i].hitWallRight) {
                    enemies[i].moveLeft=true;
                    enemies[i].moveRight=false;
                } else if (enemies[i].hitWallLeft) {
                    enemies[i].moveLeft=false;
                    enemies[i].moveRight=true;
                }
            }
        }

        public function moveCharacter(char:Object,timeDiff:Number) {
            if (timeDiff < 1) return;

            var verticalChange:Number=char.dy*timeDiff+timeDiff*gravity;
            if (verticalChange>15.0) verticalChange=15.0;
            char.dy+=timeDiff*gravity;


            var horizontalChange=0;
            var newAnimState:String="stand";
            var newDirection:int=char.direction;
            if (char.moveLeft){
                // wa
                horizontalChange = -char.walkSpeed*timeDiff;
                newAnimState="walk";
                newDirection=-1;
            } else if (char.moveRight){
                // walk right
                horizontalChange = char.walkSpeed*timeDiff;
                newAnimState="walk";
                newDirection=1;
            }

            if (char.jump) {
                // start jump
                char.jump = false;
                char.dy = -char.jumpSpeed;
                verticalChange = -char.jumpSpeed;
                newAnimState = "jump";
            }

            // assume no wall hit, and hanging in air
            char.hitWallRight = false;
            char.hitWallLeft = false;
            char.inAir = true;

            // find new vertical position
            var newY:Number = char.mc.y + verticalChange;

            // loop through all fixed objects to see if character has landed
            for(var i:int=0;i<fixedObjects.length;i++) {
                if ((char.mc.x+char.width/2 > fixedObjects[i].leftside) && (char.mc.x-char.width/2 < fixedObjects[i].rightside)) {
                    if ((char.mc.y <= fixedObjects[i].topside) && (newY > fixedObjects[i].topside)) {
                        newY = fixedObjects[i].topside;
                        char.dy = 0;
                        char.inAir = false;
                        break;
                    }
                }
            }

            // find new horizontal position
            var newX:Number = char.mc.x + horizontalChange;

            // loop through all objects to see if character has bumped into a wall
            for(i=0;i<fixedObjects.length;i++) {
                if ((newY > fixedObjects[i].topside) && (newY-char.height < fixedObjects[i].bottomside)) {
                    if ((char.mc.x-char.width/2 >= fixedObjects[i].rightside) && (newX-char.width/2 <= fixedObjects[i].rightside)) {
                        newX = fixedObjects[i].rightside+char.width/2;
                        char.hitWallLeft = true;
                        break;
                    }
                    if ((char.mc.x+char.width/2 <= fixedObjects[i].leftside) && (newX+char.width/2 >= fixedObjects[i].leftside)) {
                        newX = fixedObjects[i].leftside-char.width/2;
                        char.hitWallRight = true;
                        break;
                    }
                }
            }

            // set position of character
            char.mc.x = newX;
            char.mc.y = newY;

            // set animation state
            if (char.inAir) {
                newAnimState = "jump";
            }
            char.animstate = newAnimState;

            // move along walk cycle
            if (char.animstate == "walk") {
                char.animstep += timeDiff/60;
                if (char.animstep > char.walkAnimation.length) {
                    char.animstep = 0;
                }
                char.mc.gotoAndStop(char.walkAnimation[Math.floor(char.animstep)]);

            // not walking, show stand or jump state
            } else {
                char.mc.gotoAndStop(char.animstate);
            }

            // changed directions
            if (newDirection != char.direction) {
                char.direction = newDirection;
                char.mc.scaleX = char.direction;
            }
        }

        public function scrollWithHero(){
            var stagePosition:Number = gamelevel.x+hero.mc.x;
            var rightEdge:Number = stage.stageWidth-edgeDistance;
            var leftEdge:Number = edgeDistance;
            if (stagePosition > rightEdge){
                gamelevel.x -= (stagePosition-rightEdge);
                if (gamelevel.x < -(gamelevel.width-stage.stageWidth)) gamelevel.x = -(gamelevel.width-stage.stageWidth);
            }
            if (stagePosition < leftEdge){
                gamelevel.x += (leftEdge-stagePosition);
                if (gamelevel.x > 0)gamelevel.x=0;
            }
        }

        public function checkCollisions(){

            // enemies
            for(var i:int=enemies.length-1;i>=0;i--){
                if (hero.mc.hitTestObject(enemies[i].mc)){


                    if (hero.inAir && (hero.dy>0)){
                        enemyDie(i);
                    } else {
                        heroDie();
                    }
                }
            }

            for(i=otherObjects.length-1;i>=0;i--) {
                if (hero.mc.hitTestObject(otherObjects[i])) {
                    getObject(i);
                }
            }
        }

        public function enemyDie(enemyNum:int) {
            var pb:PointBurst = new PointBurst(gamelevel,"Zetsu Extinct!",enemies[enemyNum].mc.x,enemies[enemyNum].mc.y-20);
            gamelevel.removeChild(enemies[enemyNum].mc);
            enemies.splice(enemyNum,1);
        }

        public function heroDie() {
            // show dialog box
            var dialog:Dialog = new Dialog();
            dialog.x = 175;
            dialog.y = 100;
            addChild(dialog);

            if (playerLives == 0) {
                gameMode = "gameover";
                dialog.message.text = "Game Over!";
            } else {
                gameMode = "dead";
                dialog.message.text = "Yoi Failed...";
                playerLives--;
            }

            hero.mc.gotoAndPlay("die");
        }

        public function getObject(objectNum:int) {
            if (otherObjects[objectNum] is Treasure) {
                var pb:PointBurst = new PointBurst(gamelevel,100,otherObjects[objectNum].x,otherObjects[objectNum].y);
                gamelevel.removeChild(otherObjects[objectNum]);
                otherObjects.splice(objectNum,1);
                addScore(100);


            } else if (otherObjects[objectNum] is Key) {
                pb = new PointBurst(gamelevel,"Got Key!" ,otherObjects[objectNum].x,otherObjects[objectNum].y);
                playerObjects.push("Key");
                gamelevel.removeChild(otherObjects[objectNum]);
                otherObjects.splice(objectNum,1);


            } else if (otherObjects[objectNum] is Door) {
                if (playerObjects.indexOf("Key") == -1) return;
                if (otherObjects[objectNum].currentFrame == 1) {
                    otherObjects[objectNum].gotoAndPlay("open");
                    levelComplete();
                }


            } else if (otherObjects[objectNum] is Chest) {
                otherObjects[objectNum].gotoAndStop("open");
                gameComplete();
            }

        }

        public function addScore(numPoints:int) {
            gameScore += numPoints;
            scoreDisplay.text = String(gameScore);
        }

        // update player lives
        public function showLives() {
            livesDisplay.text = String(playerLives);
        }

        // level over, bring up dialog
        public function levelComplete() {
            gameMode = "done";
            var dialog:Dialog = new Dialog();
            dialog.x = 175;
            dialog.y = 100;
            addChild(dialog);
            dialog.message.text = "Level Complete!";
        }

        public function gameComplete() {
            gameMode = "gameover";
            var dialog:Dialog = new Dialog();
            dialog.x = 175;
            dialog.y = 100;
            addChild(dialog);
            dialog.message.text = "You Got the Treasure!";
        }

            public function clickDialogButton(event:MouseEvent) {
            removeChild(MovieClip(event.currentTarget.parent));

            // new life, restart, or go to next level
            if (gameMode == "dead") {
                // reset hero
                showLives();
                hero.mc.x = hero.startx;
                hero.mc.y = hero.starty;
                gameMode = "play";
            } else if (gameMode == "gameover") {
                cleanUp();
                gotoAndStop("start");
            } else if (gameMode == "done") {
                cleanUp();
                nextFrame();
            }

            // give stage back the keyboard focus
            stage.focus = stage;
        }           

        // clean up game
        public function cleanUp() {
            removeChild(gamelevel);
            this.removeEventListener(Event.ENTER_FRAME,gameLoop);
            stage.removeEventListener(KeyboardEvent.KEY_DOWN,keyDownFunction);
            stage.removeEventListener(KeyboardEvent.KEY_UP,keyUpFunction);
        }

    }
}