Reputation: 19
I keep getting this ArgumentError: Error #1063: Argument count mismatch on Car(). Expected 1, got 0. I'm confused cause I am passing staggerPosition to Car(). but it still says it is expecting 1 argument. If that is not what the error means how do I fix it? I double-checked all of my connections.
...
package {
import flash.display.*;
import flash.events.*;
public class cityAPP2 extends MovieClip {
private var carList: Array;
private var nCars: int = 16;
public function cityApp2() {
//TASK 1: ADD 16 CARS
carList = new Array();
var staggerPosition: int = 15;
for (var i: int = 0; i < nCars; i++) {
var car: Car = new Car(staggerPosition);
staggerPosition += 20;
car.x = car.mX;
car.y = car.mY;
addChild(car);
carList.push(car);
}
//TASK 2: REGISTER A LISTENER EVENT
addEventListener(Event.ENTER_FRAME, update);
}
public function update(event: Event) {
for (var i: int = 0; i < nCars; i++) {
carList[i].moveIt();
carList[i].x = carList.mx;
}
}
}
}
package {
import flash.display.*;
import flash.events.*;
public class Car extends MovieClip {
//DATA MEMBERS
public var mX: int;
public var mY: int;
public var directionFactor: int;
public var velocity: Number;
public var endZone: int;
public function Car(yPosition:int) {
this.mY = yPosition;
//TASK 1: COMPUTE THE DIRECTION
this.directionFactor = (Math.floor(Math.random() * 2) == 0) ? -1 : 1;
//TASK 2: SET THE SCALE, mX, mY, AND ENDZONE
this.scaleX = this.directionFactor;
if (this.directionFactor == -1) {
this.endZone = 800;
} else {
this.endZone = -100;
}
this.mX = endZone;
//TASK 3: SET THE VELOCITY TO RUN A RANDOM VALUE
this.velocity = Math.floor(Math.random() * 15 + 2) * this.directionFactor;
}
public function moveIt(): void {
//TASK 1: UPDATE THE X LOCATION OF THE CAR
this.mX += this.velocity;
trace(this.mX);
// TASK 2: ROTATE THE WHEELS OF THE CAR
//TASK 3: CHECK IF THE CAR HAS MOVED OFF THE SCREEN
if (this.directionFactor == -1 && this.mX < -200 || this.directionFactor == 1 && this.mX > 850) {
this.mX = endZone;
}
}
}
}
...
Upvotes: 0
Views: 38
Reputation: 4649
You likely have an instance of Car
on the stage somewhere (not created in code). When you do this the constructor will be called with no arguments.
You can either remove that instance from the stage or add a default value for your argument so it won't cause an error:
public function Car(yPosition:int = 0) {
...
}
Upvotes: 1