动作脚本中的参数计数不匹配

问题描述 投票:0回答:1

我一直收到此ArgumentError:错误#1063:Car()上的参数计数不匹配。期望值为1,为0。我很困惑,因为我将staggerPosition传递给Car()。但它仍然表示希望有1个论点。如果不是那样的话,该错误意味着如何解决?我仔细检查了所有连接。

...

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;
            }
        }
    }

}

...

actionscript-3
1个回答
0
投票

您可能在某个位置的舞台上有一个Car的实例(不是用代码创建的)。当您执行此操作时,将不带任何参数地调用构造函数。

您可以从舞台中删除该实例,也可以为您的参数添加默认值,这样就不会导致错误:

public function Car(yPosition:int = 0) { 
   ...
}
© www.soinside.com 2019 - 2024. All rights reserved.