将Number类型的值隐式强制转换为不相关的类型flash.display:MovieClip

时间:2016-05-26 09:30:20

标签: actionscript-3 flash flash-builder

当我尝试通过函数传递MovieClip时,我收到错误:

“将Number类型的值隐式强制转换为不相关的类型flash.display:MovieClip”

房间生成课程:

public var generatedRoom:Array;

public function enemyPack():void
    {
        //trace(generatedRoom[createdRooms]);
        var random:int = Main.getRandom(0,5);

        switch(random)
        {
            case 0:
                Main.spawnEnemy(roomX+Main.getRandom(50, room.width-50),generatedRoom[createdRooms],roomY+Main.getRandom(50, room.height-50));
                break;
        }
    }

敌人类:

public function spawn(setX:int,setY:int, inRoom:MovieClip ,b:int = 0):void
    {
        timeToSlow = Main.getRandom(500,1500)
        type = b;
        isDestroyed = false;
        switch(type)
        {
            case 0:
                life = 100 + (Math.pow(Main.dific,4));

                maxLife = life;
                model = new MC_EnemigoD();
                bulletSpeed = Main.getRandom(3,6);
                timeToMove = 400;
                bulletModel = new MC_BulletE();
                speed = 1 + (Main.nivel)/2;
                aggro = 250;
                break;
            case 1:
                life = 125 + (Math.pow(Main.dific,4));
                maxLife = life;
                model = new MC_EnemigoC();
                speed = 0.5 /*+ (Main.nivel)/2*/;
                break;
            case 2:
                life = 500 + (Math.pow(Main.dific,4));
                maxLife = life;
                model = new MC_BossM();
                speed = 1 + (Main.nivel)/2;
                timeToMove = Main.getRandom(400,600);
                bulletModel = new MC_BulletC();
                bulletSpeed = Main.getRandom(6,9);
                timeToShoot = Main.getRandom(1500,2000);
                aggro = 400;
                break;
            case 3:
                life = 400 + (Math.pow(Main.dific,4));
                maxLife = life;
                model = new MC_Troll();
                speed = 0.6 /* + (Main.nivel)/2*/;
                break;
            case 4:
                life = 1000 + (Math.pow(Main.dific,4));
                maxLife = life;
                model = new MC_BossB();
                model.scaleX = 0.5;
                model.scaleY = 0.5;
                speed = 3 + (Main.nivel)/2;
                break;
        }
        model.addChild(shadow);


        //Main.render.
        Main.render.addChild(model);
        model.gotoAndPlay("spawn")
        model.y = setY;
        model.x = setX;
        realHeight = model.height;
        realWidth = model.width;

        shadow.scaleX = model.scaleX + 0.1;
        shadow.scaleY = model.scaleY;
        shadow.x = (model.hitBox.width/2)+6-(shadow.width/2);
        shadow.y = (model.hitBox.height)-9;

        model.setChildIndex(shadow, 0);

        model.addChild(hpBar);
        hpBar.addChild(hpBarColor);
        hpBarColor.scaleY = 0.9;
        hpBarColor.scaleX = 0.97;
        hpBarColor.y = 1;
        hpBarColor.x = 1;
        hpBar.scaleY = 0.7;
        hpBar.x = (model.hitBox.width/2)+5-(hpBar.width/2);
        hpBar.y = (model.hitBox.height)+(hpBar.height);

        model.hitBox.visible = false;
    }

主要课程:

public static function spawnEnemy(setX:int,setY:int, inRoom:MovieClip, t:int = 0):void
    {
        //trace(setX,setY)
        var temp:Enemy = new Enemy();
        temp.spawn(setX,setY, inRoom, t);
        allEnemies.push(temp);
    }

当我跟踪变量时,它返回[object MC_“myMovieClip”]

1 个答案:

答案 0 :(得分:1)

如果我猜到导致错误的行
看起来像是spawnEnemy来电

Main.spawnEnemy(roomX+Main.getRandom(50, room.width-50),//int
                generatedRoom[createdRooms],//a MovieClip?
                roomY+Main.getRandom(50, room.height-50)//int
                );//(int, MovieClip(?), int)

没有正确的参数顺序:

spawnEnemy(setX:int,
           setY:int, 
           inRoom:MovieClip, 
           t:int = 0)//(int, int, MovieClip)