错误#2025两次

时间:2014-10-09 13:54:18

标签: actionscript-3

package 
{
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.ui.Keyboard;
    import flash.events.KeyboardEvent;
    import flash.events.MouseEvent;


    public class supportForce extends MovieClip
    {
        private var Player1Child:Player1Actual = new Player1Actual();
        private var Player2Child:Player2Actual = new Player2Actual();
        private var GreenLightLeft:Projectile1 = new Projectile1();
        private var GreenLightRight:Projectile2 = new Projectile2();
        private var NeonChild:mcNeonPlayer = new mcNeonPlayer();
        private var _keyDownStatus:Object = {};
        private var defaultSpeed:int = 10;
        private var Player1Lock:Boolean = false;
        private var Player2Lock:Boolean = false;
        private var Player1Left:Boolean = false;
        private var Player2Left:Boolean = true;
        private var greenLightLeft:Boolean = true;
        private var Player1CD:int = 0;
        private var Player1Ready:Boolean = true;
        private var Player1Hit:Boolean = false;
        private var Player1X:int;
        private var Player1Y:int;
        private var NeonX:int;
        private var NeonY:int;
        private var NeonCD:int = 0;
        private var NeonDuration:int = 240;
        private var NeonUse:Boolean = false;
        public function supportForce()
        {
            this.addEventListener(Event.ENTER_FRAME, general);
            stage.addEventListener(KeyboardEvent.KEY_DOWN, onDown);
            stage.addEventListener(KeyboardEvent.KEY_UP, onUp);
            stage.addEventListener(Event.ENTER_FRAME, keyCheck);
            btnStart.addEventListener(MouseEvent.CLICK, clickStart);
            btnAbout.addEventListener(MouseEvent.CLICK, clickAbout);
            btnDust.addEventListener(MouseEvent.CLICK, clickDust);
        }
        private function general(event:Event)
        {
            Player1X = Player1Child.x;
            Player1Y = Player1Child.y;
            NeonX = NeonChild.x;
            NeonY = NeonChild.y;
            GreenLightLeft.x -=  (defaultSpeed * 2);
            GreenLightRight.x +=  (defaultSpeed * 2);
            //status_text = NeonCD;
            if (NeonDuration > 0 && NeonUse == true)
            {
                NeonDuration -=  1;
            }
            else if (NeonDuration == 0 && NeonUse == true)
            {
                NeonUse = false;
                removeChild(NeonChild);
                addChild(Player1Child);
                Player1Child.x = NeonX;
                Player1Child.y = NeonY;
            }
            if (NeonCD > 0)
            {
                NeonCD -=  1;
            }
            trace(NeonCD);
            if (Player1Child.BladeInstance.hitTestObject(Player2Child) && Player1CD <= 0 && Player1Child.BladeInstance.alpha != 0)
            {
                if (Player1Left == true)
                {
                    Player2Child.x -=  defaultSpeed;
                    Player1Hit = true;
                    Player1CD = 8;
                    //trace("G");
                }
                if (Player1Left == false)
                {
                    Player2Child.x +=  defaultSpeed;
                    Player1Hit = true;
                    Player1CD = 8;
                    //trace("G");
                }
            }
            if (Player1Ready == false)
            {
                Player1CD -=  1;
            }
            if (Player1CD <= 0)
            {
                Player1Ready = true;
                Player1CD = 0;
            }
            else
            {
                Player1Ready = false;
            }
            if (Player1Left == true)
            {
                if (Player1Child.x <= (0 + Player1Child.width))
                {
                    Player1Child.x = (0 + Player1Child.width);
                }
                if (Player1Child.x >= 550)
                {
                    Player1Child.x = 550;
                }
                if (Player1Child.y >= 400)
                {
                    Player1Child.y = 400;
                }
                if (Player1Child.y <= (0 + Player1Child.height))
                {
                    Player1Child.y = (0 + Player1Child.height);
                }
            }
            else if (Player1Left == false)
            {
                if (Player1Child.x <= 0)
                {
                    Player1Child.x = 0;
                }
                if (Player1Child.x >= (550 - Player1Child.width))
                {
                    Player1Child.x = (550 - Player1Child.width);
                }
                if (Player1Child.y <= 0)
                {
                    Player1Child.y = 0;
                }
                if (Player1Child.y >= (400 - Player1Child.height))
                {
                    Player1Child.y = (400 - Player1Child.height);
                }
            }
            if (Player2Child.x <= Player2Child.width)
            {
                Player2Child.x = Player2Child.width;
            }
            if (Player2Child.x >= 550)
            {
                Player2Child.x = 550;
            }
            if (Player2Child.y >= (400 - Player2Child.height))
            {
                Player2Child.y = 400 - Player2Child.height;
            }
            if (Player2Child.y <= 0)
            {
                Player2Child.y = 0;
            }
        }
        private function onUp(e:KeyboardEvent):void
        {
            _keyDownStatus[e.keyCode] = false;
        }
        private function onDown(e:KeyboardEvent):void
        {
            _keyDownStatus[e.keyCode] = true;
        }
        private function keyCheck(event:Event)
        {
            if (_keyDownStatus[37])
            {
                if (Player1Left == false)
                {
                    Player1Left = true;
                    Player1Child.rotation +=  180;
                    Player1Child.y += (Player1Child.height - 5);
                    Player1Child.x +=  Player1Child.width;
                }
                Player1Child.x -=  defaultSpeed;
            }
            if (_keyDownStatus[39])
            {
                if (Player1Left == true)
                {
                    Player1Left = false;
                    Player1Child.rotation +=  180;
                    Player1Child.y -= (Player1Child.height - 5);
                    Player1Child.x -=  Player1Child.width;
                }
                Player1Child.x +=  defaultSpeed;
            }
            if (_keyDownStatus[38])
            {
                Player1Child.y -=  defaultSpeed;
            }
            if (_keyDownStatus[40])
            {
                Player1Child.y +=  defaultSpeed;
            }
            if (_keyDownStatus[96] && Player1Ready == true)
            {
                Player1Child.play();
                Player1Ready = false;
            }
            if (_keyDownStatus[97] && NeonCD <= 0)
            {
                removeChild(Player1Child);
                stage.addChild(NeonChild);
                NeonChild.x = Player1X;
                NeonChild.y = Player1Y;
                NeonCD = 480;
                NeonUse = true;
                Player1Lock = false;
            }
            if (_keyDownStatus[65])
            {
                if (Player2Left == false)
                {
                    Player2Left = true;
                    Player2Child.rotation -=  180;
                    Player2Child.y -= (Player2Child.height - 5);
                    Player2Child.x -=  Player2Child.width;
                }
                Player2Child.x -=  defaultSpeed;
            }
            if (_keyDownStatus[68])
            {
                if (Player2Left == true)
                {
                    Player2Left = false;
                    Player2Child.rotation +=  180;
                    Player2Child.y += (Player2Child.height - 5);
                    Player2Child.x +=  Player2Child.width;
                }
                Player2Child.x +=  defaultSpeed;
            }
            if (_keyDownStatus[87])
            {
                Player2Child.y -=  defaultSpeed;
            }
            if (_keyDownStatus[83])
            {
                Player2Child.y +=  defaultSpeed;
            }
            if (_keyDownStatus[90])
            {
                if (Player2Left == true)
                {
                    var GreenLightLeft:Projectile1 = new Projectile1();
                    stage.addChild(GreenLightLeft);
                    GreenLightLeft.x = Player2Child.x;
                    GreenLightLeft.y = Player2Child.y;
                    greenLightLeft = true;
                }
                if (Player2Left == false)
                {
                    var GreenLightRight:Projectile2 = new Projectile2();
                    stage.addChild(GreenLightRight);
                    GreenLightRight.x = (Player2Child.x);
                    GreenLightRight.y = (Player2Child.y - Player2Child.height);
                    greenLightLeft = false;
                }
            }
        }
        private function clickStart(event:MouseEvent):void
        {
            gotoAndStop(2);
        }
        private function clickAbout(event:MouseEvent):void
        {

        }
        private function clickDust(event:MouseEvent):void
        {

        }
    }

}

Numpad 1 (97)时效果很好,但第二次出现此错误。

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
    at flash.display::DisplayObjectContainer/removeChild()
    at supportForce/keyCheck()

所以我计划在10秒或240帧之后删除NeonChild,但它会出现此错误。

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
    at flash.display::DisplayObjectContainer/removeChild()
    at supportForce/general()

如果你无法理解我想说的话,那就是实际.fla和.as的链接

files

2 个答案:

答案 0 :(得分:1)

如果您不知道要删除的displayObject的父级,则可以编写

mc.parent.removeChilte(mc);

其中mc是要删除的movieclip

答案 1 :(得分:0)

改为使用

this.parent.removeChild(mc);

其中mc是MovieClip。