Actionscript 3 AS3:类can';我找不到其他类与之交互

Actionscript 3 AS3:类can';我找不到其他类与之交互,actionscript-3,flash,Actionscript 3,Flash,所以我在我的一个敌人类中为我的flash游戏准备了这个代码 package { import flash.events.*; import flash.display.*; import flash.geom.*; public class JumpBall extends MovieClip { var MTL:MovieClip = MovieClip(root); var charMTL:MovieCli

所以我在我的一个敌人类中为我的flash游戏准备了这个代码

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

    public class JumpBall extends MovieClip 
    {
        var MTL:MovieClip = MovieClip(root);
        var charMTL:MovieClip;
        var bullet:Bullet = new Bullet;

        public function JumpBall() 
        {
            this.addEventListener(Event.ENTER_FRAME, EnemyBallUpdate);

        }

        function EnemyBallUpdate(event:Event):void 
        {
            charMTL = MTL.char1;

            var enemy:Rectangle = this.getBounds(this);
            var enemy_matrix:Matrix = this.transform.matrix;
            var enemyBitmap:BitmapData = new BitmapData(enemy.width, enemy.height, true, 0);
                enemyBitmap.draw(this,enemy_matrix);

            enemy_matrix.tx = this.x - enemy.x;
            enemy_matrix.ty = this.y - enemy.y;

            var char:Rectangle = charMTL.getBounds(this);
            var char_matrix:Matrix = charMTL.transform.matrix;
            var charBitmap:BitmapData = new BitmapData(char.width, char.height, true, 0);
                charBitmap.draw(charMTL,char_matrix);

            char_matrix.tx = charMTL.x - char.x;
            char_matrix.ty = charMTL.y - char.y;

            var enemyPoint:Point = new Point(enemy.x, enemy.y);
            var charPoint:Point = new Point(char.x, char.y);

            if(enemyBitmap.hitTest(enemyPoint, 0, charBitmap, charPoint, 0) && MTL.currentFrame == 2)
            {

                if(MTL.HP == 0)
                {
                    MTL.RemoveListeners();
                    MTL.vcam_2.x = 400.2;
                    MTL.vcam_2.y = 224.9;
                    MTL.gotoAndStop(3);
                    MTL.HP = 3;
                    MTL.CC = 0;
                    MTL.removeChild(charMTL);
                }else{              
                    MTL.removeKeyboardEvts();
                    MTL.KeysOFF();
                    MTL.fade_mc.gotoAndPlay(2);
                    charMTL.gotoAndStop(1);
                    MTL.ySpeed = 0;
                    MTL.removeChild(charMTL);
                }
            }
            enemyBitmap.dispose();
            charBitmap.dispose();

        }

        public function removeJumpBallEL(event:Event):void
        {
                this.removeEventListener(Event.ENTER_FRAME, EnemyBallUpdate);
        }

    }

}
进入第2帧时,我得到一个愚蠢的错误:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at JumpBall/EnemyBallUpdate()
我不明白为什么全班同学不能和char1 MovieClip(我游戏中的角色)对话。 对于重置框,我有相同类型的类,但该类使用的是
.hitTestPoint
方法。没有错误。 我试图将我的敌人添加到数组中,以便与bullet类交互

以下是主要的时间线代码:

function addJumpBall():void
    {
    var jumpball:JumpBall = new JumpBall;
    jumpball.x = 673;
    jumpball.y = 318;
    addChild(jumpball);

    jumpball.addEventListener(Event.REMOVED, jumpballRemoved);
    JumpBallArray.push(jumpball);
    }

function jumpballRemoved(event:Event):void
    {
   event.currentTarget.removeEventListener(Event.REMOVED, jumpballRemoved); 
    JumpBallArray.splice(JumpBallArray.indexOf(event.currentTarget), 1);
    }   

addJumpBall();

谢谢任何愿意帮助我的人

var MTL:MovieClip=MovieClip(根);那条线甚至比跳球运动员跑得早。此时“root”为空。在构造函数中,“root”也将为null。这似乎解决了它!我把它移到了构造器里面。谢谢!还可以尝试设置
启用debuggin
,以便您可以看到错误发生在哪一行!;)调试显示我的错误在charMTL=MTL.char1上;线