//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
您需要發佈更多的代碼。我會建議看一下函數的源代碼 - 它可能需要一個Event作爲參數,或者類似的東西。當你將'null'作爲參數傳遞時會發生什麼? –
我在上面添加了它們,你能看看有什麼不對嗎? –
不是真的 - 它看起來好像你已經定義了一個類的實例,但是你沒有包含類定義。然而,@馬蒂華萊士擴大了我以前的評論。我相當確信他的解決方案將爲您工作。 –