where's the problem?

6 posts

Flag Post

hey, so i’m trying to learn AS3 by this guide: http://gamedev.michaeljameswilliams.com/2008/09/22/avoider-game-tutorial-2/

i’m at part 2 at the moment, but i bumped into an error, i was doing the “Taking Control of the Enemy” part, and when i finish it, it gives me an error

“D:\AvoiderFlashGame – MS\Classes\AvoiderGame.as, Line 15 1137: Incorrect number of arguments. Expected no more than 0.
"

This is the AvoiderGame.as

package
{
	import flash.display.MovieClip;
	import flash.utils.Timer;
	import flash.events.TimerEvent;

	public class AvoiderGame extends MovieClip
	{
		public var enemy:Enemy;
		public var gameTimer:Timer;
		public var avatar:Avatar;
		
		public function AvoiderGame()
		{
			enemy = new Enemy( 100, -15 );
			addChild( enemy );
			
			avatar = new Avatar();
			addChild( avatar);
			avatar.x = mouseX;
			avatar.y = mouseY;
			
			gameTimer = new Timer( 25 );
			gameTimer.addEventListener( TimerEvent.TIMER, onTick );
			gameTimer.start();
		 
		}
		
		public function onTick( timerEvent:TimerEvent ):void
		{
			enemy.MoveDownABit();
			avatar.x = mouseX;
			avatar.y = mouseY;
			
			if ( avatar.hitTestObject( enemy ) )
			{
				gameTimer.stop();
			}
		}
	}
}

I’m using Adobe flash CS6, i’ve done everything like the guide says, but i can’t figure out how to fix this.

 
Flag Post

Is your Enemy class’ contructor like that?

public function Enemy( startX:Number, startY:Number )

EDIT: Oh, you posted it on Oct 12 :D

 
Flag Post

Just check that your Enemy class constructor takes two parameters. I’m pretty sure it doesn’t.

 
Flag Post

I think its the game timer
gameTimer = new Timer( 25 );

its supposed to be gameTimer = new Timer (25,0);
you need the 2nd number to tell how many times you want the timer to run. use 0 if you want to keep repeating the timer.

 
Flag Post
Originally posted by FlashGrenade:

I think its the game timer
gameTimer = new Timer( 25 );

its supposed to be gameTimer = new Timer (25,0);
you need the 2nd number to tell how many times you want the timer to run. use 0 if you want to keep repeating the timer.

According to Adobe AS3 reference , the second argument is optional (and anyways, it wouldn’t have said “expected no more than 0” if that was the case). Homever, in the tutorial the constructor of Enemy takes two arguments.

 
Flag Post

This one has already been answered, but let’s go through the steps for debugging, just so you know what to do next time.

First, look at the error. It gives you a file (AvoiderGame.as) and a line number (15). That’s this line:

enemy = new Enemy( 100, -15 );

So that’s where the error’s coming from.

Now look at the error description: “Incorrect number of arguments. Expected no more than 0.” (The term “argument” may be a little confusing, but it isn’t too hard to look up.)

So in this case, “100” is an argument, and “-15” is an argument, for a total of two arguments. The error states that there should be no more than 0 arguments, so you have to remove both. The revised line is simply this:

enemy = new Enemy();

But you still want to set the x and y coordinates, right? Even if you can’t pass them as arguments, you can handle it like you handle avatar’s coordinates:

enemy.x = 100;
enemy.y = -15;