2014-10-09 81 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。

相關問題