Reputation: 795
I've got (to me) a strange error. As far as I can tell I'm doing everything correct, however I keep getting the error bellow.
ArgumentError: Error #1063: Argument count mismatch on Enemy(). Expected 2, got 0.
As you can see, when initializing my class Enemy it expects two arguments and gets one. However, as far as I can tell it's not the case.
Where it is called.
function startHandle(evt:MouseEvent):void{
enemy = new Enemy(1090, 189);
gotoAndStop(2);
Player.stop();
currentLevel = 1;
}
Then the Enemy class
public function Enemy(xLocation:int, yLocation:int){
trace(xLocation);
trace(yLocation);
// constructor code
x = xLocation;
y = yLocation;
trace(x);
trace(y);
}
The output I get from this is as follows.
1090
189
1090
189
ArgumentError: Error #1063: Argument count mismatch on Enemy(). Expected 2, got 0.
at flash.display::MovieClip/gotoAndStop()
at Project_fla::MainTimeline/startHandle()
As far as I can tell it gets the two values, knows it has them, sets them. But still gives an error. Anyone got an idea?
Upvotes: 0
Views: 134
Reputation: 18747
Most likely you have a pre-placed enemy on some frame. Since the default constructor for any DisplayObject
descendant wants 0 arguments, anything created in Flash GUI makes Flash compiler to make a constructor call with 0 arguments. To circumvent this (and find that pesky enemy that throws you up) give default values for the constructor like this:
public function Enemy(xLocation:int=0, yLocation:int=0){
And watch when an enemy will appear at (0,0), debug that point and eliminate creation of any unneeded enemy instances.
Upvotes: 2