错误1009:全局$ init和其他人

时间:2014-06-12 11:19:15

标签: actionscript-3 runtime-error

我正在使用ActionScript3制作游戏,我遇到了一个问题。 自从我上次保存并重新启动电脑后,运行代码时出现 1009错误

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Tower1()
at GameOfGames$cinit()
at global$init()

我正在使用4个类和1个fla文件。以下代码:

主要班级:

    package  {

    import flash.display.*;
    import flash.ui.*;
    import flash.events.*;

    public class GameOfGames extends MovieClip {
        //Initial var's
        //startScreen
        public var startButton = new start_btn;
        public var creditsButton = new credits;
        public var background1 = new bg1;
        public var txt_lannister1 = new txt_lannister;
        //HowToPlay
        public var gameScreen1 = new GameScreen;
        public var goButton = new playGame;
        //Sprites
        public var enemy1 = new nedStark;
        public  var twr_1 = new Tower1;
        public static var twr_2 = new Tower1;
        public var turnBlock1 = new turnBlock;
        public var turnBlock2 = new turnBlock;
        public var turnBlock3 = new turnBlock;
        public static var towerArray:Array = []
        //Map
        public  var throne1 = new Throne();
        public var lanes1 = new lanes;
        public var emptyInterface = new interfaceEmpty;
        public var cash:int = 100;

        public function GameOfGames() {
            // Listeners
            startButton.addEventListener(MouseEvent.CLICK, clickStartButton);
            //CreditsButyton.addEventListener(MouseEvent.CLICK, clickCreditsButton);
            goButton.addEventListener(MouseEvent.CLICK, clickGoButton);
            addEventListener(Event.ENTER_FRAME, update);
            // Initial
            stage.addChild(background1);
                background1.x = stage.stageWidth /2;
                background1.y = stage.stageHeight /2;

            stage.addChild(txt_lannister1);
                txt_lannister1.x = stage.stageWidth /2;
                txt_lannister1.y = stage.stageHeight /2 - 50;

            stage.addChild(startButton);
                startButton.x = 860;
                startButton.y = 590;

            stage.addChild(creditsButton);
                creditsButton.x = 100;
                creditsButton.y = 590;

            // -130   5 


        }
        public function update (e:Event)
        {
            if (twr_1.hitTestPoint(enemy1.x-50, enemy1.y, true))
            {
                enemy1.gotoAndPlay(28);
                //removeEventListener(Event.ENTER_FRAME, update);
                nedStark.speedX = 0;
                enemy1.x += 3;
            }

            if (twr_2.hitTestPoint(enemy1.x-50, enemy1.y, true))
            {
                enemy1.gotoAndPlay(28);
                //removeEventListener(Event.ENTER_FRAME, update);
                nedStark.speedX = 0;
                enemy1.x += 3;
            }
            if (turnBlock1.hitTestPoint(enemy1.x-50, enemy1.y, true))
            {
                nedStark.speedX = 1.5;
                nedStark.speedY = 3;
            }
            if (throne1.hitTestPoint(enemy1.x-50, enemy1.y, true))
                {
                    enemy1.gotoAndPlay(28);
                    trace("throneattack");
                    nedStark.speedX = 0;
                    nedStark.speedY = 0;
                    enemy1.x += 3;
                }

            if (enemy1.currentFrame == 42)
            {
                Tower1.currentHp -= 50;
                Tower1.changeHpBar();
            }
        }
        public function clickStartButton (e:MouseEvent)
        {
            stage.removeChild(startButton);
            stage.removeChild(creditsButton);
            stage.removeChild(txt_lannister1);
            stage.removeChild(background1);
            stage.addChild(gameScreen1);
                gameScreen1.x = 960/2;
                gameScreen1.y = 640/2;
            stage.addChild(goButton);
                goButton.x = 860;
                goButton.y = 590;
        }

        public function clickGoButton (e:MouseEvent)
        {
            stage.removeChild(goButton);
            stage.removeChild(gameScreen1)




            stage.addChild(lanes1);
                lanes1.x = 100;
                lanes1.y = -60;
                lanes1.scaleY = 1.15;
            stage.addChild(turnBlock1);
                turnBlock1.x = 180,35;
                turnBlock1.y = 430,85;
                turnBlock1.scaleY = 3.55;
            stage.addChild(turnBlock2);
                turnBlock2.x = 180,35;
                turnBlock2.y = 640/2 - 75;
                turnBlock2.scaleY = 3.55;
            stage.addChild(turnBlock3);
                turnBlock3.x = 180,35;
                turnBlock3.y = 20;
                turnBlock3.scaleY = 3.55;

            stage.addChild(twr_1);
                twr_1.x = 319,3;
                twr_1.y = 480;


            stage.addChild(throne1);
                throne1.x = 20;
                throne1.y = 640/2 - 75

            stage.addChild(enemy1);
                enemy1.x = stage.stageWidth *0.95;
                enemy1.y = stage.stageHeight /2 + 100;
                enemy1.scaleX = 0.40;
                enemy1.scaleY = 0.40;

            stage.addChild(emptyInterface);
                emptyInterface.y =  520;
                emptyInterface.x = 0;
            ;
        }



    }

}

接口类:

 package  {
    import flash.events.*;
    import flash.display.*;
    import flash.text.*;

    public class interfaceEmpty extends MovieClip{
            public static var  currentWave:int = 0;
            public static var currentCash:int = 1000;

        public function interfaceEmpty() {
            addEventListener(Event.ENTER_FRAME, newWave)
            next_wave.addEventListener(MouseEvent.CLICK, nextWave);
            twr_1_drag1.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
            twr_1_drag1.addEventListener(MouseEvent.MOUSE_UP, stopDragging)

        }
        public function newWave(e:Event):void
        {
            this.waveText.text = currentWave.toString();
            this.cashText.text = currentCash.toString();

        }
        public function nextWave (e:MouseEvent)
        {
            currentWave += 1;

        }
        public function startDragging (e:MouseEvent)
        {
            twr_1_drag1.startDrag();
            twr_1_drag1.gotoAndStop(2);
        }
        public function stopDragging (e:MouseEvent)
        {
            twr_1_drag1.stopDrag();
            addTower();
            twr_1_drag1.x = 215,3;
            twr_1_drag1.y = 8;
            twr_1_drag1.gotoAndStop(1);
        }
        public function addTower()
        {
            addChild(GameOfGames.twr_2);
                GameOfGames.twr_2.x = mouseX;
                GameOfGames.twr_2.y = mouseY;
        }

    }

}

敌人类:

    package  {

    import flash.display.*;
    import flash.events.*;


    public class nedStark extends MovieClip {
        public var maxHp:int = 100;
        public var currentHp:int = maxHp;
        public var percentHp:Number = currentHp / maxHp;
        public var healthbar = new lifeBar;
        public static var speedX:Number = 3;
        public static var speedY:Number = 0;


        public function nedStark() {
            addEventListener(Event.ENTER_FRAME, update);
            addEventListener(MouseEvent.CLICK, clickEnemy);
            addChild(healthbar);

            healthbar.x = -2,6;
            healthbar.y = -197,75;
            healthbar.scaleX = 0.15;
            healthbar.scaleY = 0.15;
        }
        public function update (e:Event)
        {
            x -= speedX;
            y -= speedY
            if (currentFrame == 25)
            {
                this.parent.removeChild(this);
            }
        }
        public function clickEnemy(e:MouseEvent)
        {
            trace(currentHp);
            currentHp -= 10;

            if(currentHp <= 0)
            {
                removeEventListener(MouseEvent.CLICK, clickEnemy);
                speedX = 0;
                currentHp = 0;
                gotoAndPlay(2);
                trace("udeadbro?");
                neddie.mouseEnabled = false;
                interfaceEmpty.currentWave += 1;
                interfaceEmpty.currentCash += 100;
            }

            changeHpBar ();
        }
        public function changeHpBar():void
        {
            percentHp = currentHp / maxHp;
            healthbar.barColor.scaleX = percentHp;
        }
    }

}

最后(塔)班:

    package 
{

    import flash.display.*;
    import flash.events.*;


    public class Tower1 extends MovieClip
    {
        public  static var maxHp:int = 100;
        public  static var currentHp:int = maxHp;
        public  static var percentHp:Number = currentHp / maxHp;
        public  static var healthbar = new lifeBar();
        public static var death:Boolean = false;

        public function Tower1()
        {
            GameOfGames.towerArray.push(this);
            addChild(healthbar);
            healthbar.x = -2.6;
            healthbar.y = 4.6;
            healthbar.scaleX = 0.12;
            healthbar.scaleY = 0.07;

            addEventListener(Event.ENTER_FRAME, update);
        }
        public function update(e:Event)
        {
            if (currentHp == 0)
            {
                gotoAndPlay(2);
                currentHp = 0;
                removeEventListener(Event.ENTER_FRAME, update);
                this.parent.removeChild(this);
                death = true;
            }
            if (currentFrame == 44)
            {
                this.parent.removeChild(this);
            }
        }
        public static function changeHpBar()
        {
            percentHp = currentHp / maxHp;
            healthbar.barColor.scaleX = percentHp;
        }

    }

我不知道如何在此错误后继续前进。这可能是一个非常小的错误,但我不知道解决方案。

提前致谢!

0 个答案:

没有答案