2017-02-13 6 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()という関数はありません。エラーは、null(空で初期化されていない)オブジェクト参照のフィールドにアクセスしようとしていることを意味します。 [ファイル]> [パブリッシュ設定]> [デバッグを許可]を選択して、エラーを生成する正確な行を確認します。 – 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 Main/onKey() ArgumentError:エラー#1063:Main/goBack()の引数の数が一致しません。 0を期待して、1を得ました。 – Fahad

+0

私はイベントの議論をするのを忘れた。あなたは自分でそれを理解したはずです。 – Organis

+0

はい、私はそれをしました。ありがとう@オルガン。私は仕事について1つの質問があります。ゲームを開始してスタートボタンを押すと、すべてのキーボードイベントが停止し、マウスをクリックすると動作します。私が解決できる方法はありますか? – Fahad

関連する問題