2014-10-05 58 views
1
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 _keyDownStatus:Object = {}; 
     private var defaultSpeed:Number = 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:Number = 0; 
     private var Player1Ready:Boolean = true; 
     private var Player1Hit: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) 
     { 
      if (Player1Child.BladeInstance.hitTestObject(Player2Child)) 
      { 
       if (Player1Left == true) 
       { 
        Player2Child.x -= defaultSpeed; 

       } 
       if (Player1Left == false) 
       { 
        Player2Child.x += defaultSpeed; 

       } 
      } 
      if (Player1Ready == false) 
      { 
       Player1CD -= 1; 
      } 
      if (Player1CD <= 0) 
      { 
       Player1Ready = true; 
      } 
      if (Player1Child.x <= 0) 
      { 
       Player1Child.x = 0; 
      } 
      if (Player1Child.x >= 550) 
      { 
       Player1Child.x = 550; 
      } 
      if (Player1Child.y >= (400 - Player1Child.height)) 
      { 
       Player1Child.y = 400 - Player1Child.height; 
      } 
      if (Player1Child.y <= 0) 
      { 
       Player1Child.y = 0; 
      } 
      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) 
      { 
       Player1Ready = false; 
       Player1CD = 8; 
       Player1Child.play(); 
      } 
      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) 
       { 
        stage.addChild(GreenLightLeft); 
        GreenLightLeft.x = Player2Child.x; 
        GreenLightLeft.y = Player2Child.y; 
        greenLightLeft = true; 
       } 
       if (Player2Child == false) 
       { 
        stage.addChild(GreenLightRight); 
        GreenLightRight.x = (Player2Child.x - Player2Child.width); 
        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 
     { 

     } 
    } 

} 

第一幀具有前奏像開始文件不能訪問空對象引用的屬性或方法,等和框架2具有MovieClip實例稱爲Player1Child和MovieClip內部是另一個名爲BladeInstance的MovieClip。當我運行它時,它會在輸出框中給出Error#1009,並且錯誤(我猜)是在「常規」函數中。 您可以下載.as文件的實際.fla文件,地址爲https://www.mediafire.com/folder/i93zm31p7513m/A_Game。 如果可以的話,請爲兩個動畫片段中的「轉動」部分提供另一個更簡單的方法(雖然它已經很好地工作了)。提前謝謝你。AS3 - 錯誤#1009:在supportForce /普通()

+0

順便說一下邏輯是我的哈哈。 :D – InfiniteParadox 2014-10-05 17:14:34

回答

0

好吧,我想通了,我的想法?
那麼我得到它沒有任何錯誤運行。

在Organised.fla進入你的符號「Player1Actual」

您層上「刀鋒」,你會發現第1幀是空的。 (這是錯誤發生),它試圖在符號'Player1Actual'的第1幀上找到'BladeInstance'。

我發現一個非常簡單的解決方案就是將您的符號'BladePlayer1'複製到圖層'Blade'上的第1幀。

確保第1幀「BladePlayer1」仍然有「BladeInstance」 然後,只需設置幀1的「BladePlayer1」阿爾法爲0

那固定的錯誤給我一個實例名稱。 希望這有助於。

+0

非常感謝!最後工作! – InfiniteParadox 2014-10-07 02:33:02

0

錯誤#1009俗稱Null Pointer Exception.

這意味着你試圖用訪問屬性「」 (點)的空或未定義的變量。

您需要弄清楚未定義的變量是什麼。

例如。尋找錯誤發生在哪條線上。
也許使用trace("var: "var);

有關於計算器這個話題堆只是搜索

Error #1009: Cannot access a property or method of a null object reference at
,你應該找到如何解決。

還檢查了https://forums.adobe.com/message/4641806

+0

實際上,未知事物是BladeInstance,因爲它在MovieClip Player1Child的frame1中不存在(它在Player1Child的frame2中播放)。我有沒有希望?先謝謝你。 – InfiniteParadox 2014-10-05 17:13:40

+0

這應該是一個簡單的修復。在stackoverflow上有很多類似的帖子。在給出參考之前,你可能正在處理「階段」。用以下代碼開始你的代碼:'addEventListener(Event.ADDED_TO_STAGE,init);'以及此偵聽器的私有函數init(e:Event)的處理函數:void removeEventListener(Event.ADDED_TO_STAGE,init); //在此之後編寫代碼 }'如果您正在編寫框架(在框架中編寫AS3代碼)正如錯誤所述 - 您正在調用一些對象屬性或方法爲null。您的調試器將能夠指向您嘗試在幀2上調用的空對象。 – 2014-10-05 17:56:00

+0

真的很抱歉,但你能否找到我沒有線索,我在上面的描述中添加了該文件的鏈接。很抱歉打擾你,但謝謝! – InfiniteParadox 2014-10-06 03:14:57