2012-01-18 51 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 –

相关问题