2014-10-09 62 views
0
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 
     { 

     } 
    } 

} 

当我按下数字键盘1键(97)但它第二次,它给出这个错误时,它完美的作品。 ArgumentError:错误#2025:提供的DisplayObject必须是调用者的子项。因此,我计划在10秒或240帧后移除NeonChild,但它会给出这个错误。 ArgumentError:错误#2025:提供的DisplayObject必须是调用者的子项。 () at flash.display :: DisplayObjectContainer/removeChild() at supportForce/general() 如果你不明白我在说什么,这是指向实际.fla和.as文件的链接。 https://www.mediafire.com/folder/i93zm31p7513m/A_Game。先谢谢你。错误#2025两次。

+0

无论孩子是否有父母或孩子是否存在,您都试图移除孩子。在做任何事之前你应该检查这些情况。两个给出的答案都是明显的错误和错误顺便说一句。 – BotMaster 2014-10-09 19:33:33

回答

1

,如果你不知道displayObject的,要删除的父母,你可以写

mc.parent.removeChilte(mc); 

其中MC是影片剪辑,要删除

+0

我试过了,但是显示错误#1119通过静态类型Class的引用访问可能未定义的属性父项。 – InfiniteParadox 2014-10-09 14:58:57

+0

你确定父类型是DisplayObject吗? – 2014-10-09 15:11:31

+0

是的,谢谢你,但我找到了解决方案。谢谢,因为解决方案部分来自您的答案。 – InfiniteParadox 2014-10-09 15:31:04

0

用这个代替

this.parent.removeChild(mc); 

其中mc是MovieClip。

相关问题