首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Flash CS6不识别函数和包

Flash CS6不识别函数和包
EN

Stack Overflow用户
提问于 2017-02-01 20:14:36
回答 1查看 64关注 0票数 0

我正在为技术学生协会做3D游戏。

我是一个业余程序员,所以这可能就是我有这些问题的原因。一开始,它添加了第3层,Flash不承认私有函数所在的包。请告诉我,这是密码:

代码语言:javascript
复制
package { 
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;

    public class Dungeon3D extends MovieClip {
        public var viewSprite:Sprite; // everything
        public var worldSprite:Sprite; // walls, ceiling, floor, coins

        // references to objects
        public var map:Map; // mc to use for wall and coin positions
        public var map2:Map2; // mc to use for wall and coin positions      
        public var squares:Array; // blocks on map
        public var worldObjects:Array; // walls and coins

        private var charPos:Point; // player location

        // keyboard input
        private var leftArrow, rightArrow, upArrow, downArrow: Boolean;

        // car direction and speed
        private var dir:Number = 90;
        private var speed:Number = 0;

        //mrb:  variables
        private var gameMode:String = "start";      
        public var playerObjects:Array;     
        private var gameScore:int;
        private var playerLives:int;        

        // start game
        public function startGame() {
            gameMode = "play";          
            playerObjects = new Array();
            gameScore = 0;
            playerLives = 3;
        }       
        public function startDungeon3D() {
            viewSprite = new Sprite();
            viewSprite.x = 275;
            viewSprite.y = 250;
            viewSprite.z = -500;
            addChild(viewSprite);

            // add an inner sprite to hold everything, lay it down
            worldSprite = new Sprite();
            viewSprite.addChild(worldSprite);
            worldSprite.rotationX = -90;

            // cover above with ceiling tiles
            for(var i:int=-5;i<5;i++) {
                for(var j:int=-6;j<1;j++) {
                    var ceiling:Ceiling = new Ceiling();
                    ceiling.x = i*200;
                    ceiling.y = j*200;
                    ceiling.z = -200; // above
                    worldSprite.addChild(ceiling);
                }
            }

            // cover below with floor tiles
            for(i=-5;i<5;i++) {
                for(j=-6;j<1;j++) {
                    var floor:Floor = new Floor();
                    floor.x = i*200;
                    floor.y = j*200;
                    floor.z = 0; // below
                    worldSprite.addChild(floor);
                }
            }

            // get the game map
            map = new Map();

            // look for squares in map, and put four walls in each spot
            // also move coins up and rotate them
            worldObjects = new Array();
            squares = new Array();
            for(i=0;i<map.numChildren;i++) {
                var object = map.getChildAt(i);
                //var mc = this.gamelevel.getChildAt(i);

                if (object is Square) {
                    // add four walls, one for each edge of square
                    addWall(object.x+object.width/2, object.y, object.width, 0);
                    addWall(object.x, object.y+object.height/2, object.height, 90);
                    addWall(object.x+object.width, object.y+object.height/2, object.height, 90);
                    addWall(object.x+object.width/2, object.y+object.height, object.width, 0);

                    // remember squares for collision detection
                    squares.push(object);

                } else if (object is Coin) {
                    object.z = -50; // move up
                    object.rotationX = -90; // turn to face player
                    worldSprite.addChild(object);
                    worldObjects.push(object); // add to array fo zSort

                } else if (object is Key) {
                    object.z = -50; // move up
                    object.rotationX = -90; // turn to face player
                    worldSprite.addChild(object);
                    worldObjects.push(object); // add to array fo zSort

                } else if (object is Chest) {
                    object.z = -50; // move up
                    object.rotationX = -90; // turn to face player
                    worldSprite.addChild(object);
                    worldObjects.push(object); // add to array fo zSort

                }  else if (object is Door) {
                    object.z = 77; // move up
                    object.rotationX = 90; // turn to face player
                    worldSprite.addChild(object);
                    worldObjects.push(object); // add to array fo zSort
                }
            }

            // keep track of virtual position of character
            charPos = new Point(0,0);

            // arrange all walls and coins for distance
            zSort();

            // respond to key events
            stage.addEventListener(KeyboardEvent.KEY_DOWN,keyPressedDown);
            stage.addEventListener(KeyboardEvent.KEY_UP,keyPressedUp);

            // advance game
            addEventListener(Event.ENTER_FRAME, moveGame);
        }

        public function startDungeon3D2() {
        // create the world and center it
            viewSprite = new Sprite();
            viewSprite.x = 275;
            viewSprite.y = 250;
            viewSprite.z = -500;
            addChild(viewSprite);

            // add an inner sprite to hold everything, lay it down
            worldSprite = new Sprite();
            viewSprite.addChild(worldSprite);
            worldSprite.rotationX = -90;

            // cover above with ceiling tiles
            for(var i:int=-5;i<5;i++) {
                for(var j:int=-6;j<1;j++) {
                    var ceiling:Ceiling = new Ceiling();
                    ceiling.x = i*200;
                    ceiling.y = j*200;
                    ceiling.z = -200; // above
                    worldSprite.addChild(ceiling);
                }
            }

            // cover below with floor tiles
            for(i=-5;i<5;i++) {
                for(j=-6;j<1;j++) {
                    var floor:Floor = new Floor();
                    floor.x = i*200;
                    floor.y = j*200;
                    floor.z = 0; // below
                    worldSprite.addChild(floor);
                }
            }

            // get the game map
            map2 = new Map2();

            // look for squares in map, and put four walls in each spot
            // also move coins up and rotate them
            worldObjects = new Array();
            squares = new Array();
            for(i=0;i<map2.numChildren;i++) {
                var object = map2.getChildAt(i);
                //var mc = this.gamelevel.getChildAt(i);

                if (object is Square) {
                    // add four walls, one for each edge of square
                    addWall(object.x+object.width/2, object.y, object.width, 0);
                    addWall(object.x, object.y+object.height/2, object.height, 90);
                    addWall(object.x+object.width, object.y+object.height/2, object.height, 90);
                    addWall(object.x+object.width/2, object.y+object.height, object.width, 0);

                    // remember squares for collision detection
                    squares.push(object);

                } else if (object is Coin) {
                    object.z = -50; // move up
                    object.rotationX = -90; // turn to face player
                    worldSprite.addChild(object);
                    worldObjects.push(object); // add to array fo zSort

                } else if (object is Key) {
                    object.z = -50; // move up
                    object.rotationX = -90; // turn to face player
                    worldSprite.addChild(object);
                    worldObjects.push(object); // add to array fo zSort

                } else if (object is Chest) {
                    object.z = -50; // move up
                    object.rotationX = -90; // turn to face player
                    worldSprite.addChild(object);
                    worldObjects.push(object); // add to array fo zSort

                }  else if (object is Door) {
                    object.z = -50; // move up
                    object.rotationX = -90; // turn to face player
                    worldSprite.addChild(object);
                    worldObjects.push(object); // add to array fo zSort
                }
            }

        public function startDungeon3D3() {
        // create the world and center it
            viewSprite = new Sprite();
            viewSprite.x = 275;
            viewSprite.y = 250;
            viewSprite.z = -500;
            addChild(viewSprite);

            // add an inner sprite to hold everything, lay it down
            worldSprite = new Sprite();
            viewSprite.addChild(worldSprite);
            worldSprite.rotationX = -90;

            // cover above with ceiling tiles
            for(var i:int=-5;i<5;i++) {
                for(var j:int=-6;j<1;j++) {
                    var ceiling:Ceiling = new Ceiling();
                    ceiling.x = i*200;
                    ceiling.y = j*200;
                    ceiling.z = -200; // above
                    worldSprite.addChild(ceiling);
                }
            }

            // cover below with floor tiles
            for(i=-5;i<5;i++) {
                for(j=-6;j<1;j++) {
                    var floor:Floor = new Floor();
                    floor.x = i*200;
                    floor.y = j*200;
                    floor.z = 0; // below
                    worldSprite.addChild(floor);
                }
            }

            // get the game map
            map3 = new Map3();

            // cover below with floor tiles
            for(i=-5;i<5;i++) {
                for(j=-6;j<1;j++) {
                    var floor:Floor = new Floor();
                    floor.x = i*200;
                    floor.y = j*200;
                    floor.z = 0; // below
                    worldSprite.addChild(floor);
                }
            }

            // look for squares in map, and put four walls in each spot
            // also move coins up and rotate them
            worldObjects = new Array();
            squares = new Array();
            for(i=0;i<map3.numChildren;i++) {
                var object = map3.getChildAt(i);
                //var mc = this.gamelevel.getChildAt(i);

                if (object is Square) {
                    // add four walls, one for each edge of square
                    addWall(object.x+object.width/2, object.y, object.width, 0);
                    addWall(object.x, object.y+object.height/2, object.height, 90);
                    addWall(object.x+object.width, object.y+object.height/2, object.height, 90);
                    addWall(object.x+object.width/2, object.y+object.height, object.width, 0);

                    // remember squares for collision detection
                    squares.push(object);

                } else if (object is Coin) {
                    object.z = -50; // move up
                    object.rotationX = -90; // turn to face player
                    worldSprite.addChild(object);
                    worldObjects.push(object); // add to array fo zSort

                } else if (object is Key) {
                    object.z = -50; // move up
                    object.rotationX = -90; // turn to face player
                    worldSprite.addChild(object);
                    worldObjects.push(object); // add to array fo zSort

                } else if (object is Chest) {
                    object.z = -50; // move up
                    object.rotationX = -90; // turn to face player
                    worldSprite.addChild(object);
                    worldObjects.push(object); // add to array fo zSort

                }  else if (object is Door) {
                    object.z = -50; // move up
                    object.rotationX = -90; // turn to face player
                    worldSprite.addChild(object);
                    worldObjects.push(object); // add to array fo zSort
                }
            }
            // keep track of virtual position of character
            charPos = new Point(0,0);

            // arrange all walls and coins for distance
            zSort();

            // respond to key events
            stage.addEventListener(KeyboardEvent.KEY_DOWN,keyPressedDown);
            stage.addEventListener(KeyboardEvent.KEY_UP,keyPressedUp);

            // advance game
            addEventListener(Event.ENTER_FRAME, moveGame);
        }       

        // add a vertical wall 
        public function addWall(x, y, len, rotation) {
            var wall:Wall = new Wall();
            wall.x = x;
            wall.y = y;
            wall.z = -wall.height/2;
            wall.width = len;
            wall.rotationX = 90;
            wall.rotationZ = rotation;
            worldSprite.addChild(wall);
            worldObjects.push(wall);
        }

        // set arrow variables to true
        public function keyPressedDown(event:KeyboardEvent) {
            if (event.keyCode == 37) {
                leftArrow = true;
            } else if (event.keyCode == 39) {
                rightArrow = true;
            } else if (event.keyCode == 38) {
                upArrow = true;
            } else if (event.keyCode == 40) {
                downArrow = true;
            }
        }

        // set arrow variables to false
        public function keyPressedUp(event:KeyboardEvent) {
            if (event.keyCode == 37) {
                leftArrow = false;
            } else if (event.keyCode == 39) {
                rightArrow = false;
            } else if (event.keyCode == 38) {
                upArrow = false;
            } else if (event.keyCode == 40) {
                downArrow = false;
            }
        }

        private function turnPlayer(d) {

            // change direction
            dir += d;

            // rotate world to change view
            viewSprite.rotationY = dir-90;
        }

        // main game function
        public function moveGame(e) {

            // see if turning left or right
            var turn:Number = 0;
            if (leftArrow) {
                turn = 10;
            } else if (rightArrow) {
                turn = -10;
            }

            // turn
            if (turn != 0) {
                turnPlayer(turn);
            }

            // if up arrow pressed, then accelerate, otherwise decelerate
            speed = 0;
            if (upArrow) {
                speed = 10;
            } else if (downArrow) {
                speed = -10;
            }

            // move
            if (speed != 0) {
                movePlayer(speed);
            }

            // re-sort objects
            if ((speed != 0) || (turn != 0)) {
                zSort();
            }

            // see if any coins hit
            checkCoins();
            checkKey();
            checkChest();       
            checkDoor();
        }

        public function movePlayer(d) {
            // calculate current player area

            // make a rectangle to approximate space used by player
            var charSize:Number = 50; // approximate player size
            var charRect:Rectangle = new Rectangle(charPos.x-charSize/2, charPos.y-charSize/2, charSize, charSize);

            // get new rectangle for future position of player
            var newCharRect:Rectangle = charRect.clone();
            var charAngle:Number = (-dir/360)*(2.0*Math.PI);
            var dx:Number = d*Math.cos(charAngle);
            var dy:Number = d*Math.sin(charAngle);
            newCharRect.x += dx;
            newCharRect.y += dy;

            // calculate new location
            var newX:Number = charPos.x + dx;
            var newY:Number = charPos.y + dy;

            // loop through squares and check collisions
            for(var i:int=0;i<squares.length;i++) {

                // get block rectangle, see if there is a collision
                var blockRect:Rectangle = squares[i].getRect(map);
                if (blockRect.intersects(newCharRect)) {

                    // horizontal push-back
                    if (charPos.x <= blockRect.left) {
                        newX +=  blockRect.left - newCharRect.right;
                    } else if (charPos.x >= blockRect.right) {
                        newX += blockRect.right - newCharRect.left;
                    }

                    // vertical push-back
                    if (charPos.y >= blockRect.bottom) {
                        newY +=  blockRect.bottom - newCharRect.top;
                    } else if (charPos.y <= blockRect.top) {
                        newY +=  blockRect.top - newCharRect.bottom;
                    }
                }

            }

            // move character position
            charPos.y = newY;
            charPos.x = newX;

            // move terrain to show proper view
            worldSprite.x = -newX;
            worldSprite.z = newY;
        }

        // spin coins and see if any have been hit
        private function checkCoins() { 
            // look at all objects
            for(var i:int=worldObjects.length-1;i>=0;i--) {
                // only look at coins
                if (worldObjects[i] is Coin) {
                    // spin it!
                    worldObjects[i].rotationZ += 10;
                    // check distance from character
                    var dist:Number = Math.sqrt(Math.pow(charPos.x-worldObjects[i].x,2)+Math.pow(charPos.y-worldObjects[i].y,2));
                    // if close enough, remove coin
                    if (dist < 50) {
                        worldSprite.removeChild(worldObjects[i]);
                        worldObjects.splice(i,1);
                    }
                }
            }
        }

        // spin coins and see if any have been hit
        private function checkKey() {   
            // look at all objects
            for(var i:int=worldObjects.length-1;i>=0;i--) {
                // only look at coins
                if (worldObjects[i] is Key) {
                    // spin it!
                    worldObjects[i].rotationZ += 10;
                    // check distance from character
                    var dist:Number = Math.sqrt(Math.pow(charPos.x-worldObjects[i].x,2)+Math.pow(charPos.y-worldObjects[i].y,2));
                    // if close enough, remove coin
                    if (dist < 50) {
                        getObject(i);  // mrb:  call to getobject                       
                        worldSprite.removeChild(worldObjects[i]);
                        worldObjects.splice(i,1);
                    }
                }
            }
        }       

        // spin coins and see if any have been hit
        private function checkChest() {
            // look at all objects
            for(var i:int=worldObjects.length-1;i>=0;i--) {
                // only look at coins
                if (worldObjects[i] is Chest) {
                    // spin it!
                    worldObjects[i].rotationZ += 10;
                    // check distance from character
                    var dist:Number = Math.sqrt(Math.pow(charPos.x-worldObjects[i].x,2)+Math.pow(charPos.y-worldObjects[i].y,2));
                    // if close enough and have the key end the level; don't remove if no key
                    if (dist < 50) {
                        getObject(i);  // mrb:  call to getobject   
                        //worldSprite.removeChild(worldObjects[i]);
                        //worldObjects.splice(i,1);
                    }
                }
            }
        }   

        // spin coins and see if any have been hit
        private function checkDoor() {
            // look at all objects
            for(var i:int=worldObjects.length-1;i>=0;i--) {
                // only look at coins
                if (worldObjects[i] is Door) {
                    // spin it!
                    worldObjects[i].rotationZ += 10;
                    // check distance from character
                    var dist:Number = Math.sqrt(Math.pow(charPos.x-worldObjects[i].x,2)+Math.pow(charPos.y-worldObjects[i].y,2));
                    // if close enough and have the key end the level; don't remove if no key
                    if (dist < 50) {
                        getObject(i);  // mrb:  call to getobject   
                        //worldSprite.removeChild(worldObjects[i]);
                        //worldObjects.splice(i,1);
                    }
                }
            }
        }   


        // player collides with objects
        public function getObject(objectNum:int) {
            // award points for treasure
            if (worldObjects[objectNum] is Treasure) {
                //var pb:PointBurst = new PointBurst(map,100,worldObjects[objectNum].x,worldObjects[objectNum].y);
                //gamelevel.removeChild(otherObjects[objectNum]);
                //otherObjects.splice(objectNum,1);
                //addScore(100);

            // got the key, add to inventory
            } else if (worldObjects[objectNum] is Key) {
                //pb = new PointBurst(gamelevel,"Got Key!" ,otherObjects[objectNum].x,otherObjects[objectNum].y);
                playerObjects.push("Key");
                trace(playerObjects.indexOf("Key"));
                //gamelevel.removeChild(otherObjects[objectNum]);
                //otherObjects.splice(objectNum,1);

            // hit the door, end level if hero has the key
            } else if (worldObjects[objectNum] is Door) {
                if (playerObjects.indexOf("Key") == -1) return;  // i don't have the key
                if (worldObjects[objectNum].currentFrame == 1) {  // i got the key  
                    worldObjects[objectNum].gotoAndPlay("open");            
                    levelComplete();
                }

            // got the chest, game won, if hero has the key
            } else if (worldObjects[objectNum] is Chest) {
                if (playerObjects.indexOf("Key") == -1) return;
                trace(worldObjects[objectNum].currentFrame);
                if (worldObjects[objectNum].currentFrame == 1) {
                    worldObjects[objectNum].gotoAndStop("open");
                    gameComplete();
                }
            }
        }

        // 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!";
        }           

        // game over, bring up dialog
        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!";
        }

        // dialog button clicked
        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);

            stage.removeEventListener(KeyboardEvent.KEY_DOWN,keyPressedDown);
            stage.removeEventListener(KeyboardEvent.KEY_UP,keyPressedUp);
            this.removeEventListener(Event.ENTER_FRAME, moveGame);          
            removeChild(viewSprite);            
        }           

        // sort all objects so the closest ones are highest in the display list
        private function zSort() {
            var objectDist:Array = new Array();
            for(var i:int=0;i<worldObjects.length;i++) {
                var z:Number = worldObjects[i].transform.getRelativeMatrix3D(root).position.z;
                objectDist.push({z:z,n:i});
            }
            objectDist.sortOn( "z", Array.NUMERIC | Array.DESCENDING );
            for(i=0;i<objectDist.length;i++) {
                worldSprite.addChild(worldObjects[objectDist[i].n]);
            }
        }
    }
}
}

这些都是我现在遇到的错误,即使代码在那里。文件名为Dungeon3D.as

C:\Users\school\Desktop\Dungeon3DV3\Dungeon3D.as,第217 1114行:公共属性只能在包中使用。C:\Users\school\Desktop\Dungeon3DV3\Dungeon3D.as,第3241114行:公共属性只能在包内使用。C:\Users\school\Desktop\Dungeon3DV3\Dungeon3D.as,第3371114行:公共属性只能在包中使用。C:\Users\school\Desktop\Dungeon3DV3\Dungeon3D.as,第3501114行:公共属性只能在包中使用。C:\Users\school\Desktop\Dungeon3DV3\Dungeon3D.as,第362行1013:只能在类属性定义上使用私有属性。C:\Users\school\Desktop\Dungeon3DV3\Dungeon3D.as,第372 1114行:公共属性只能在包中使用。C:\Users\school\Desktop\Dungeon3DV3\Dungeon3D.as,第412行1114:公共属性只能在包中使用。C:\Users\school\Desktop\Dungeon3DV3\Dungeon3D.as,第4651013行:只能在类属性定义上使用私有属性。C:\Users\school\Desktop\Dungeon3DV3\Dungeon3D.as,第4841013行:只能在类属性定义上使用私有属性。C:\Users\school\Desktop\Dungeon3DV3\Dungeon3D.as,第5041013行:只能在类属性定义上使用私有属性。C:\Users\school\Desktop\Dungeon3DV3\Dungeon3D.as,第5241013行:只能在类属性定义上使用私有属性。C:\Users\school\Desktop\Dungeon3DV3\Dungeon3D.as,第545 1114行:公共属性只能在包中使用。C:\Users\school\Desktop\Dungeon3DV3\Dungeon3D.as,第581 1114行:公共属性只能在包中使用。C:\Users\school\Desktop\Dungeon3DV3\Dungeon3D.as,第591 1114行:公共属性只能在包中使用。C:\Users\school\Desktop\Dungeon3DV3\Dungeon3D.as,第601114行:公共属性只能在包中使用。C:\Users\school\Desktop\Dungeon3DV3\Dungeon3D.as,第6241114行:公共属性只能在包中使用。C:\Users\school\Desktop\Dungeon3DV3\Dungeon3D.as,第637行1013:只能在类属性定义上使用私有属性。

每当我更改代码本身的位置时,仍然会出现相同的错误。闪光灯搞砸了?或者代码是从另一个文件夹中提取的?

EN

回答 1

Stack Overflow用户

发布于 2017-02-09 12:14:44

}方法之后,您错过了startDungeon3D2()。把它加到第214行。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41988869

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档