2017-02-13 4 views
0

오류 # 1009 : null 개체 참조의 속성이나 메서드에 액세스 할 수 없습니다. MethodInfo-10()의 이 코드를 실행하는 동안이 오류가 발생합니다. 누구든지 내가 뭘 잘못하고 있는지 말해 줄 수 있어요. 오류가있는 곳이나 오류의 행을 표시하지 않습니다. 감사합니다동작 스크립트 3.0 오류

package 
{ 
    import flash.events.MouseEvent; 
    import flash.display.MovieClip; 
    import flash.events.KeyboardEvent; 
    import flash.ui.Keyboard; 
    public class Main extends MovieClip 
    { 
     public function Main() 
     { 
      stop(); 
      start_btn.addEventListener(MouseEvent.CLICK, gothere); 
      function gothere(clickInfo:MouseEvent) 
      { 
       start_btn.removeEventListener(MouseEvent.CLICK, gothere); 
       nextFrame(); 
      } 

      stage.addEventListener(KeyboardEvent.KEY_DOWN, key_pressed); 
      function key_pressed(event:KeyboardEvent):void 
      { 
       switch (event.keyCode) 
       { 
        case Keyboard.UP : 
         { 
          player.y += -5; 
          if ((wall1.hitTestPoint(player.x - player.width/2, player.y - player.height/2,true)) || (wall2.hitTestPoint(player.x - player.width/2, player.y - player.height/2,true))) 
          { 
           player.y += 5; 
           nextFrame(); 
           playagain_btn.addEventListener(MouseEvent.CLICK, goback); 
           function goback(event:MouseEvent):void 
           { 
            playagain_btn.removeEventListener(MouseEvent.CLICK, goback); 
            prevFrame(); 
           } 


          } 
          else if ((wall1.hitTestPoint(player.x + player.width/2, player.y - player.height/2,true)) || (wall2.hitTestPoint(player.x + player.width/2, player.y - player.height/2,true))) 
          { 
           player.y += 5; 
           nextFrame(); 
           playagain_btn.addEventListener(MouseEvent.CLICK, goback1); 
           function goback1(event:MouseEvent):void 
           { 
            playagain_btn.removeEventListener(MouseEvent.CLICK, goback1); 
            prevFrame(); 
           } 
          } 
          else if (player.hitTestObject(finish)) 
          { 
           gotoAndStop(4); 
          } 
          break; 





         }; 
        case Keyboard.DOWN : 
         { 
          player.y += 5; 
          if ((wall1.hitTestPoint(player.x - player.width/2, player.y + player.height/2,true)) || (wall2.hitTestPoint(player.x - player.width/2, player.y + player.height/2,true))) 
          { 
           player.y += -5; 
           nextFrame(); 
           playagain_btn.addEventListener(MouseEvent.CLICK, goback2); 
           function goback2(event:MouseEvent):void 
           { 
            playagain_btn.removeEventListener(MouseEvent.CLICK, goback2); 
            prevFrame(); 
           } 
          } 
          else if ((wall1.hitTestPoint(player.x + player.width/2, player.y + player.height/2,true)) || (wall2.hitTestPoint(player.x + player.width/2, player.y + player.height/2,true))) 
          { 
           player.y += -5; 
           nextFrame(); 
           playagain_btn.addEventListener(MouseEvent.CLICK, goback3); 
           function goback3(event:MouseEvent):void 
           { 
            playagain_btn.removeEventListener(MouseEvent.CLICK, goback3); 
            prevFrame(); 
           } 
          } 
          else if (player.hitTestObject(finish)) 
          { 
           gotoAndStop(4); 
          } 
          break; 





         }; 
        case Keyboard.LEFT : 
         { 
          player.x += -5; 
          if ((wall1.hitTestPoint(player.x - player.width/2, player.y - player.height/2,true)) || (wall2.hitTestPoint(player.x - player.width/2, player.y - player.height/2,true))) 
          { 
           player.x += 5; 
           nextFrame(); 
           playagain_btn.addEventListener(MouseEvent.CLICK, goback4); 
           function goback4(event:MouseEvent):void 
           { 
            playagain_btn.removeEventListener(MouseEvent.CLICK, goback4); 
            prevFrame(); 
           } 
          } 
          else if ((wall1.hitTestPoint(player.x - player.width/2, player.y + player.height/2,true)) || (wall2.hitTestPoint(player.x - player.width/2, player.y + player.height/2,true))) 
          { 
           player.x += 5; 
           nextFrame(); 
           playagain_btn.addEventListener(MouseEvent.CLICK, goback5); 
           function goback5(event:MouseEvent):void 
           { 
            playagain_btn.removeEventListener(MouseEvent.CLICK, goback5); 
            prevFrame(); 
           } 
          } 
          else if (player.hitTestObject(finish)) 
          { 
           gotoAndStop(4); 
          } 
          break; 





         }; 
        case Keyboard.RIGHT : 
         { 
          player.x += 5; 
          if ((wall1.hitTestPoint(player.x + player.width/2, player.y - player.height/2,true)) || (wall2.hitTestPoint(player.x + player.width/2, player.y - player.height/2,true))) 
          { 
           player.x += -5; 
           nextFrame(); 
           playagain_btn.addEventListener(MouseEvent.CLICK, goback6); 
           function goback6(event:MouseEvent):void 
           { 
            playagain_btn.removeEventListener(MouseEvent.CLICK, goback6); 
            prevFrame(); 
           } 
          } 
          else if ((wall1.hitTestPoint(player.x + player.width/2, player.y + player.height/2,true)) || (wall2.hitTestPoint(player.x + player.width/2, player.y + player.height/2,true))) 
          { 
           player.x += -5; 
           nextFrame(); 
           playagain_btn.addEventListener(MouseEvent.CLICK, goback7); 
           function goback7(event:MouseEvent):void 
           { 
            playagain_btn.removeEventListener(MouseEvent.CLICK, goback7); 
            prevFrame(); 
           } 
          } 
          else if (player.hitTestObject(finish)) 
          { 
           gotoAndStop(4); 
          } 
          break; 



        } 

       } 


      } 
     } 

    } 
}; 
+0

코드에 MethodInfo-10() 함수가 없습니다. 오류는 널 (비공개, 초기화되지 않음) 객체 참조의 필드에 액세스하려고한다는 것을 의미합니다. 파일> 제작 설정> 디버깅 허용을 클릭하여 오류가 발생한 정확한 행을 확인합니다. – Organis

+0

오류 # 1009 : null 개체 참조의 속성이나 메서드에 액세스 할 수 없습니다. Function/Main/$ constructor/key_pressed()에서 \t입니다. 설정 변경 후 나타나는 오류입니다. – Fahad

+0

중첩 된 기능을 대괄호로 묶을 때 가장 많이 발생하는 오류입니다. @Organis에서 제시하는대로 Main()과 동일한 수준으로 이동하고 프로젝트의 모든 곳에 유지하십시오. 이렇게하면 반드시 디버깅 및 확장 기능이 향상됩니다. – Vesper

답변

2

중복 코드로 코드를 작성하는 것으로 시작하십시오. 또한 함수 내부에서 정의 된 함수는 함수 내부에서 정의됩니까? 너무 많은 단계에서 그렇게 잘못되었습니다.

package 
{ 
    import flash.ui.Keyboard; 

    import flash.display.MovieClip; 

    import flash.events.MouseEvent; 
    import flash.events.KeyboardEvent; 

    public class Main extends MovieClip 
    { 
     public function Main() 
     { 
      stop(); 
      start_btn.addEventListener(MouseEvent.CLICK, goThere); 
      stage.addEventListener(KeyboardEvent.KEY_DOWN, onKey); 
     } 

     private function goBack(e:MouseEvent):void 
     { 
      playagain_btn.removeEventListener(MouseEvent.CLICK, goBack); 
      prevFrame(); 
     } 

     private function goThere(clickInfo:MouseEvent):void 
     { 
      start_btn.removeEventListener(MouseEvent.CLICK, gothere); 
      nextFrame(); 

      stage.focus = stage; 
     } 

     private function testPlayer():Boolean 
     { 
      if (wall1.hitTestPoint(player.x - player.width/2, player.y - player.height/2,true) return true; 
      if (wall2.hitTestPoint(player.x - player.width/2, player.y - player.height/2,true) return true; 
      if (wall1.hitTestPoint(player.x + player.width/2, player.y - player.height/2,true) return true; 
      if (wall2.hitTestPoint(player.x + player.width/2, player.y - player.height/2,true) return true; 

      return false; 
     } 

     private function movePlayer(dx:Number, dy:Number):void 
     { 
      player.x += dx; 
      player.y += dy; 

      if (player.hitTestObject(finish)) 
      { 
       gotoAndStop(4); 
      } 
      else if (testPlayer()) 
      { 
       player.x -= dx; 
       player.y -= dy; 

       nextFrame(); 

       playagain_btn.addEventListener(MouseEvent.CLICK, goBack); 
      } 
     } 

     private function onKey(event:KeyboardEvent):void 
     { 
      switch (event.keyCode) 
      { 
       case Keyboard.UP: 
        movePlayer(0,-5); 
        break; 

       case Keyboard.DOWN: 
        movePlayer(0,5); 
        break; 

       case Keyboard.LEFT: 
        movePlayer(-5,0); 
        break; 

       case Keyboard.RIGHT: 
        movePlayer(5,0); 
        break; 
      } 
     } 
    } 
} 
+0

전 함수에 관해서는 전적으로 동의하지만, 제가이 오류를 보여주고 있다고 생각한다면 말입니다. 오류 # 1009 : null 개체 참조의 속성이나 메서드에 액세스 할 수 없습니다. \t at Main/movePlayer() \t at Main/onKey() ArgumentError : 오류 # 1063 : Main/goBack()에서 인수 개수가 일치하지 않습니다. 예상 0, 1있어. – Fahad

+0

예. 나는 사건 논쟁을 두는 것을 잊었다. 너 혼자 생각 했어야 해. – Organis

+0

예, 제가 그랬습니다. 고맙습니다. 오르가니스네. 나는 한 가지 질문을한다. 게임을 시작하고 시작 버튼을 누르면 모든 키보드 이벤트가 작동을 멈추고 화면에서 마우스를 클릭하면 작동이 시작됩니다. 내가 해결할 수있는 방법이 있나. – Fahad