2012-01-18 3 views
0
 //Handle game logic 
     mcPlayer.update(); 
     //create question 
     mcMathQu.update(); 

외부 파일의 첫 번째 "업데이트"기능이 작동하지만 인스턴스가 2 번째 외부 파일에 추가되어 오류가 발생합니다 ... (그 뒤에 3 번째 파일도 있습니다)오류 1136 : 잘못된 인수 수입니다. 예상 1 1

참고 : 코드 자체는 fla 파일의 외부 파일입니다. (그리고 난). 여전히 진행하고 (.

이 전체 기능 코드입니다. 모든 것을 파일로 개인의 외부에 제대로 연결되어,

 public function update(evt:Event) 
    { 
     //This is the game loop  


     //Handle user input 
     if (right) 
     { 
      mcPlayer.moveRight(); 
     } 
     else if (left) 
     { 
      mcPlayer.moveLeft(); 
     } 
     else 
     { 
      mcPlayer.stopMoving(); 
     } 

     if (jumping && !mcPlayer.isInAir()) 
     { 
      mcPlayer.jump(); 
     } 
     //reset jump 
     jumping = false; 

     //Handle game logic 
     mcPlayer.update(); 
     //create question 
     mcMathQu.update(); 

     for (var i = aliensArray.length - 1; i >= 0; i--) 
     { 
      aliensArray[i].update(); 
     } 

     //Check for collision between player and platforms 
     if (mcPlayer.isFallingDown()) 
     { 
      for (var j = platformsArray.length - 1; j >= 0; j--) 
      { 
       if (platformsArray[j].hitTestObject(mcPlayer.hitBox)) 
       { 
        mcPlayer.y = platformsArray[j].y; 
        mcPlayer.hitFloor(platformsArray[j]); 

        //Exit the loops 
        break; 
       } 
      } 
     } 

     //Check for collision between player and aliens 
     for (var k = aliensArray.length - 1; k >= 0; k--) 
     { 
      if (aliensArray[k].hitTestObject(mcPlayer.hitBox)) 
      { 
       if (mcPlayer.isFallingDown()) 
       { 
        //player jumped on it 
        removeChild(aliensArray[k]); 
        aliensArray.splice(k,1); 
       } 
       else 
       { 
        //player is hit 
        gotHit(); 
       } 
      } 
     } 

     //Check for Game Over 
     if (life <= 0) 
      gameOver(); 

     //Handle display 
     txtLife.text = String(life);    

     //Check for collision between portals and player 
     if (currPortal.hitTestPoint(mcPlayer.x, mcPlayer.y)) 
     { 
      if (currentLabel == "stage1") 
       gotoAndStop("stage2"); 
      else if (currentLabel == "stage2") 
      { 
       removeEventListener(Event.ENTER_FRAME, update); 
       gotoAndStop("win"); 
      } 
     } 
    } 

을 확인하고 코드와 같은 외부

package Game{ 
//Add in your import statements here 
import flash.display.*; 
import flash.events.*; 
import flash.utils.*; 

//... 

public class Maths extends MovieClip 
{ 
    //Add in your class variables here 
    //private var score:Number; 
    private var operand1:Number; 
    private var operand2:Number; 
    private var mathsign:String; 
    private var rdmSign:int; 
    private var startNewGame:Boolean; 
    //private var count:Number; 
    //private var myTimer:Timer; 
    //... 
    /* add new var, and put it as random 4 different int, 
    than use it to SET mathsign as + -/x ... 
    dun forget the 60 sec timer. 
    and minus 10 sec if ans wrongly . 
    and 1 min only 30 questions . :D 
    note : add in a end game menu + big big score :DDD 
    and a start game one also. 
    */ 
    public function MathsQuiz() 
    { 

    } 

    public function Maths() 
    { 


     //score = 0; 
     operand1 = 0; 
     operand2 = 0; 
     startNewGame = true; 
     //count = 60 ; 
     //myTimer = new Timer(1000,count); 



     //Get the game loop to execute 
     addEventListener(Event.ENTER_FRAME,update); 
     stage.addEventListener(KeyboardEvent.KEY_DOWN, checkAnswer); 
     //myTimer.addEventListener(TimerEvent.TIMER, ticktock); 
     //myTimer.start(); 


    } 




    // private function ticktock(event:TimerEvent):void 
    //{ 
    //  txtCountdown.text = String((count)-myTimer.currentCount); 
    //} 

    private function checkAnswer(evt:KeyboardEvent) 
    { 
     if (evt.keyCode == 13) 
     { 
      if (mathsign == "+" && txtResult.text == String(operand1 + operand2)) 
      { 
       //score += 10; 
      } 
      else if (mathsign == "-" && txtResult.text == String(operand1 - operand2)) 
      { 
       //score += 10; 
      } 
      else if (mathsign == "x" && txtResult.text == String(operand1 * operand2)) 
      { 
       //score += 10; 
      } 
      else if (mathsign == "÷" && txtResult.text == String(operand1/operand2)) 
      { 
       //score += 10; 
      } 
      else 
      { 
       //score -=5; 
       //count -=10; 
      } 
      startNewGame = true; 
      txtResult.text = ""; 
     } 

    } 

    public function update(evt:Event) 
    { 

     //die 
     //if (txtCountdown.text <= "0") 
     //{ 
      //score = 0; 
      //count = 60; 
      //startNewGame = true; 
     //} 
     //random sign is random. 


     if(rdmSign == 1) 
     { 
      mathsign = "+"; 
     } 
     else if(rdmSign == 2) 
     { 
      mathsign = "-"; 
     } 
     else if(rdmSign == 3) 
     { 
      mathsign = "x"; 
     } 
     else if(rdmSign == 4) 
     { 
      mathsign = "÷"; 
     } 


     //Handle user input 


     //Handle game logic 
     if (startNewGame == true) 
     { 
      var max = 12; 
      var min = 0; 
      operand1 = Math.floor(Math.random()*(max-min+1))+min; 
      operand2 = Math.floor(Math.random()*(max-min+1))+min; 
      rdmSign = Math.floor(Math.random() *4 + 1); 
      startNewGame = false; 
     } 
     //Handle display 
     txtOperand1.text = String(operand1); 
     txtOperand2.text = String(operand2); 
     txtMathsign.text = String(mathsign); 
     //txtScore.text = String(score); 
    }  

}//end class  
    }//end package 
+0

더 많은 코드를 게시해야합니다. 함수의 소스 코드를 살펴 보는 것이 좋습니다. 인수로 Event를 요구할 수도 있습니다. 인수로'null'을 전달하면 어떻게됩니까? –

+0

나는 그들을 위에 추가했다, 무엇이 잘못 볼 수 있냐? –

+0

실제로는 클래스의 인스턴스를 정의한 것처럼 보이지만 클래스 정의는 포함하지 않았습니다. 그러나 @Marty Wallace는 나의 이전의 논평을 확장했다. 나는 그의 해결책이 당신을 위해 일할 것이라고 확신합니다. –

답변

3

당신은 당신의 첫 번째 매개 변수 (evt를) 만들 null의 디폴트 값이, 그것을 매개 변수를 제공하지 않고 update()를 호출 할 거라면 :

public function update(evt:Event = null) 

이 방법을 업데이트 할 때주의하십시오. 어디서든 내부 evt의 사용을 할 경우, 당신은 if(evt != null) 또는 이와 유사한 예에 포장해야 할 것이다 :

public function update(evt:Event = null):void 
{ 
    if(evt != null) 
    { 
     trace(evt.target); 
    } 
} 

그렇지 않으면 당신은거야 어떤 멋진 폭격으로 활용하려면 다음

TypeError: Error #1009: Cannot access a property or method of a null object reference.

+0

괜찮아, 알았어, 내가해볼 게. :) –

+1

. 그것은 일했다 : D –

관련 문제