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

外部文件的第一個「更新」功能作爲文件工作,但我添加到第二個外部文件中的實例,它給了我那個錯誤...(它後面有第三個工作)錯誤1136:參數的數量不正確。預期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

不是真的 - 它看起來好像你已經定義了一個類的實例,但是你沒有包含類定義。然而,@馬蒂華萊士擴大了我以前的評論。我相當確信他的解決方案將爲您工作。 –

回答

3

如果你將要調用update()沒有給它任何參數,只是讓你的第一個參數(evt)有null默認值:

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

好的,謝謝,我會嘗試tmr :) –

+1

thks。它的工作:D –

相關問題