1

私はこれをどうするか分かりません。私はこれを1時間調べてきましたが、次のようなエラーが表示され続けています。

TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at Shooter_Enemy/shotHandler()
    at flash.utils::Timer/_timerDispatch()
    at flash.utils::Timer/tick()

デバッグすると、「seekingBullet」がステージに追加されたコード行を指します。これを解決するための助けは大歓迎です。

package 
{
    import flash.display.*;
    import flash.events.*;
    import flash.utils.Timer;

    public class Shooter_Enemy extends MovieClip
    {
        private var yMove:int = 2;
        private var shootTimer:Timer = new Timer(500);

        public function Shooter_Enemy()
        {
            this.name = "mc_shooter_enemy";
            this.addEventListener(Event.ENTER_FRAME,enemyMove);

            shootTimer.start();
            shootTimer.addEventListener(TimerEvent.TIMER,shotHandler);
        }

        public function addShooterEnemy(X:int):void
        {
            this.x = X;
            this.y = 0;
        }
        public function removeEnemy()
        {
            shootTimer.removeEventListener(TimerEvent.TIMER,shotHandler);
            shootTimer.stop();

            this.removeEventListener(Event.ENTER_FRAME,enemyMove);
            this.x = 0;
            this.y = (stage.height + this.height);
        }
        private function shotHandler(te:TimerEvent):void
        {
            var seekingBullet:SeekingBullet = new SeekingBullet();
            Main.seekingBulletArray.push(seekingBullet);
            stage.addChild(seekingBullet);
            seekingBullet.addSeekingBullet(this.x,this.y);
        }
        private function enemyMove(e:Event)
        {
            this.y +=  yMove;
        }
    }
}    
4

1 に答える 1

0

実際の場合、ステージを使用するための良い習慣は、* Event.ADDED_TO_STAGE *をリッスンしてから、次のようにアクティビティを開始することです。

package 
{
    import flash.display.*;
    import flash.events.*;
    import flash.utils.Timer;

    public class Shooter_Enemy extends MovieClip
    {
        private var yMove:int = 2;
        private var shootTimer:Timer = new Timer(500);

        public function Shooter_Enemy()
        {
            this.name = "mc_shooter_enemy";
            this.addEventListener(Event.ENTER_FRAME,enemyMove);

            shootTimer.addEventListener(TimerEvent.TIMER, shotHandler);
            addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
        }

        public function addShooterEnemy(X:int):void
        {
            this.x = X;
            this.y = 0;
        }
        public function removeEnemy()
        {
            shootTimer.removeEventListener(TimerEvent.TIMER,shotHandler);
            shootTimer.stop();

            this.removeEventListener(Event.ENTER_FRAME,enemyMove);
            this.x = 0;
            this.y = (stage.height + this.height);
        }
        private function addedToStageHandler(e:Event)
        {
            shootTimer.start();
        }
        private function shotHandler(te:TimerEvent):void
        {
            var seekingBullet:SeekingBullet = new SeekingBullet();
            Main.seekingBulletArray.push(seekingBullet);
            stage.addChild(seekingBullet);
            seekingBullet.addSeekingBullet(this.x,this.y);
        }
        private function enemyMove(e:Event)
        {
            this.y +=  yMove;
        }
    }
}
于 2013-01-22T05:32:18.540 に答える