错误1006:不是函数

雷克苏苏

尝试访问另一个类中的方法时,标题出现错误。我有一个主要的类ZombieBots,它链接到同名的影片剪辑。然后,我还有3个影片剪辑,它们在运行时都添加到了ZombieBots剪辑中,并且每个都有自己的类。

当我尝试从其他3个类之一访问ZombieBots类中的方法时,出现错误1006。

我试图在ZombieBots类中访问的函数,该函数无法访问:

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

    public class ZombieBots extends MovieClip{

        private var pLives:int;
        private var pScore:int;
        private var pSkill:int;
        private var pItems:int;
        private var characterMC:Character;
        private var cGameObjs:Array;

        public function ZombieBots() {
            /*cGameObjs = new Array();
            addCharacter();
            addItems();
            addBots();

            pLives = 5 - pSkill;
            pScore = 0;

            pItems = pSkill + 5;*/
            resetGame();
        }

        private function  addCharacter():void{
            trace("Adding the character");

            if (!characterMC){
            var myBorder:Rectangle = new Rectangle(35,35,600,480);
            var myXY:Array = [38, 400];
            var myChar:int = Math.ceil(Math.random()*3);
            var myKeys:Array = [37,39,38,40];
            var myDistance:int = myChar * 3;
            characterMC = new Character(myBorder, myXY, myKeys, myChar, myDistance);
            addChild(characterMC);
            }
            else{

                characterMC.x = 38;
                characterMC.y = 510;


                characterMC.gotoAndStop(pSkill);

            }
        }


    private function  addItems():void{
        trace("yeah boi");
        var mySkill:int = Math.ceil(Math.random() *3);
        var myMaxItems:int = mySkill + 5;
        trace(mySkill);
        trace(myMaxItems);
        trace(this);
        for (var i:int = 0; i < myMaxItems; i++){
            var thisItem:Item = new Item(this, characterMC, mySkill);
            thisItem.name = "item" + i;
            cGameObjs.push(thisItem);
            addChild(thisItem);
        }

        pSkill = mySkill;
        updateScores();
    }

        private function  addBots():void{
            trace("adding the bots bra");
            var myBorder:Rectangle =  new Rectangle(100,100,400,350);
            var mySkill:int = Math.ceil(Math.random()*3);
            var myMaxBots:int = mySkill +10;
            for (var i:int = 0; i < myMaxBots; i++){
                var thisBot:Bot = new Bot(myBorder, characterMC, mySkill);
                thisBot.name = "bot" + i;
                cGameObjs.push(thisBot);
                addChild(thisBot);

            }
        }

        private function  updateScores():void{
            scoreDisplay.text = String(pScore);
            itemsDisplay.text = String(pItems);
            livesDisplay.text = String(pLives);
            msgDisplay.text = "Orc Invasion";

        }

        public function  updateLives(myBot:MovieClip):void{
            trace("update lives");
            pLives--;
            pScore -= myBot.getPts();
            var myIndex:int = cGameObjs.indexOf(myBot);
            cGameObjs.splice(myIndex, 1);
            if (pLives > 0){
                updateScores();

            }

            else{
                gameOver(false);
            }
        }

        public function updateItems(myItem:MovieClip):void{
        trace("update items");
        pItems--;
        pScore += myItem.getPts();
        var myIndex:int = cGameObjs.indexOf(myItem);
        cGameObjs.splice(myIndex, 1);
        if (pItems > 0){
            updateScores();
        }

        else{
            gameOver(true);
        }

    }

        private function  gameOver(bool:Boolean):void{
            trace("Game over dawg");
            updateScores();
            if(bool){
                msgDisplay.text = "Good job buddy";
            }
            else{
                msgDisplay.text = "You suck dawg";
            }
            removeLeftovers();
        }

        private function  resetGame():void{
            playAgainBtn.visible = false;
            playAgainBtn.removeEventListener(MouseEvent.CLICK,playAgain);
            cGameObjs = new Array();
            addCharacter();
            addItems();
            addBots();

            pLives = 5 - pSkill;
            pScore = 0;

            pItems = pSkill + 5;
            updateScores();
        }

        private function  playAgain(evt:MouseEvent):void{
            resetGame();
        }

        private function removeLeftovers():void{
            trace("Removing leftover items and bots");
            for each(var myObj in cGameObjs){
                myObj.hasHitMe();
                myObj = null;
            }
            playAgainBtn.visible = true;
            playAgainBtn.addEventListener(MouseEvent.CLICK, playAgain);
        }





    }

}

这是我尝试在其他3个类之一中访问此函数的类:

    package  {
    import flash.display.MovieClip;
    import flash.events.*;
    import ZombieBots;

    public class Item extends MovieClip{
        private var cNumItem:int;
        private var cNumPts:int;
        private var characterMC:MovieClip;
        private var ZombieBot:ZombieBots;

        public function Item(myZB:ZombieBots, myChar:MovieClip, mySkill:int=1) {
            ZombieBot = myZB;
            cNumItem = Math.ceil(Math.random() * (mySkill * 3 + 1));
            characterMC = myChar;
            this.addEventListener(Event.ADDED_TO_STAGE,initItem);
            addEventListener(Event.ENTER_FRAME, checkCollision);
        }


        private function initItem(evt:Event):void{

            this.gotoAndStop(cNumItem);
            cNumPts = cNumItem * 25;
            setPosition();
            this.removeEventListener(Event.ADDED_TO_STAGE,initItem);
        }

        private function setPosition():void{

            this.x = (Math.ceil(Math.random() * 10)*50);
            this.y = (Math.ceil(Math.random()*10)*35);

        }

        private function checkCollision(evt:Event){
            if (characterMC.hitTestObject(this)){

                ZombieBot.updateItems(this);
                hasHitMe();
            }
        }

        public function hasHitMe():void{
            trace("remove");
            removeEventListener(Event.ENTER_FRAME, checkCollision);
            this.parent.removeChild(this);
        }

        public function getPts():int{
            return cNumPts;
        }
    }

}

有人可以帮忙吗?

典型的

updateItems不是MovieClip方法。这是ZombieBots类的方法。

将您的ZombieBots实例(我假设是根)投射为MovieClip,将仅允许您使用其类方法或已继承的方法。

试试这个 :

var zombieBotsInstance:ZombieBots = root as ZombieBots;
zombieBotsInstance.updateItems(this);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章