Copy link to clipboard
Copied
Well, it seems I've got this error in my game I'm creating (it's my first).
The full error is:
ArgumentError: Error #1063: Argument count mismatch on Bumper(). Expected 2, got 0.
This show's up when I enter frame 3 (frame 1 is start, frame 2 is Level select, frame 3 is game).
My entire code for frame 3 is:
import flash.events.MouseEvent;
stop();
var leftPressed:Boolean = false;
var rightPressed:Boolean = false;
var upPressed:Boolean = false;
var downPressed:Boolean = false;
var leftBumping:Boolean = false;
var rightBumping:Boolean = false;
var upBumping:Boolean = false;
var downBumping:Boolean = false;
var leftBumpPoint:Point = new Point(-30, -55);
var rightBumpPoint:Point = new Point(30, -55);
var upBumpPoint:Point = new Point(0, -120);
var downBumpPoint:Point = new Point(0, 0);
var scrollX:Number = 0;
var scrollY:Number = 500;
var xSpeed:Number = 0;
var ySpeed:Number = 0;
var speedConstant:Number = 4;
var frictionConstant:Number = 0.9;
var gravityConstant:Number = 1.8;
var jumpConstant:Number = -35;
var maxSpeedConstant:Number = 18;
var doubleJumpReady:Boolean = false;
var upReleasedInAir:Boolean = false;
var keyCollected:Boolean = false;
var doorOpen:Boolean = false;
var currentLevel:int = 1;
var pScore:int = 0;
var lives:int = 10;
var animationState:String = "idle";
var bulletList:Array = new Array();
var enemyList:Array = new Array();
var bumperList:Array = new Array();
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
stage.addEventListener(Event.ENTER_FRAME, loop);
addEnemiesToLevel();
lifeTxt.text=String(lives);
scoreTxt.text=String(pScore);
function addEnemiesToLevel():void
{
if(currentLevel == 1){
//Enemy 1
addEnemy(620, -115);
addBumper(500, -115);
addBumper(740, -115);
//Enemy 2
addEnemy(900, -490);
addBumper(600, -490);
addBumper(980, -490);
//Enemy 3
addEnemy(2005, -115);
addBumper(1905, -115);
addBumper(2105, -115);
//Enemy 4
addEnemy(1225, -875);
addBumper(1125, -875);
addBumper(1325, -875);
}
if(currentLevel == 2){
addEnemy(620, -115);
addBumper(500, -115);
addBumper(740, -115);
}
}
function loop(e:Event):void{
if(back.collisions.hitTestPoint(player.x + leftBumpPoint.x, player.y + leftBumpPoint.y, true)){
leftBumping = true;
} else {
leftBumping = false;
}
if(back.collisions.hitTestPoint(player.x + rightBumpPoint.x, player.y + rightBumpPoint.y, true)){
rightBumping = true;
} else {
rightBumping = false;
}
if(back.collisions.hitTestPoint(player.x + upBumpPoint.x, player.y + upBumpPoint.y, true)){
upBumping = true;
} else {
upBumping = false;
}
if(back.collisions.hitTestPoint(player.x + downBumpPoint.x, player.y + downBumpPoint.y, true)){
downBumping = true;
} else {
downBumping = false;
}
if(leftPressed){
xSpeed -= speedConstant;
player.scaleX = -1;
} else if(rightPressed){
xSpeed += speedConstant;
player.scaleX = 1;
}
if(leftBumping){
if(xSpeed < 0){
xSpeed *= -0.5;
}
}
if(rightBumping){
if(xSpeed > 0){
xSpeed *= -0.5;
}
}
if(upBumping){
if(ySpeed < 0){
ySpeed *= -0.5;
}
}
if(downBumping){
if(ySpeed > 0){
ySpeed = 0;
}
if(upPressed){
ySpeed = jumpConstant;
}
//DOUBLE JUMP
if(upReleasedInAir == true){
upReleasedInAir = false;
}
if(doubleJumpReady == false){
doubleJumpReady = true;
}
} else {
ySpeed += gravityConstant;
//DOUBLE JUMP
if(upPressed == false && upReleasedInAir == false){
upReleasedInAir = true;
}
if(doubleJumpReady && upReleasedInAir){
if(upPressed){
doubleJumpReady = false;
ySpeed = jumpConstant;
}
}
}
if(keyCollected == false){
if(player.hitTestObject(back.other.doorKey)){
back.other.doorKey.visible = false;
keyCollected = true;
trace("key collected");
}
}
if(doorOpen == false){
if(keyCollected == true){
if(player.hitTestObject(back.other.lockedDoor)){
back.other.lockedDoor.gotoAndStop(2);
doorOpen = true;
trace("door open");
}
}
}
if(xSpeed > maxSpeedConstant){
xSpeed = maxSpeedConstant;
} else if(xSpeed < (maxSpeedConstant * -1)){
xSpeed = (maxSpeedConstant * -1);
}
xSpeed *= frictionConstant;
ySpeed *= frictionConstant;
if(Math.abs(xSpeed) < 0.5){
xSpeed = 0;
}
scrollX -= xSpeed;
scrollY -= ySpeed;
back.x = scrollX;
back.y = scrollY;
sky.x = scrollX * 0.2;
sky.y = scrollY * 0.2;
if( ( leftPressed || rightPressed || xSpeed > speedConstant || xSpeed < speedConstant *-1 ) && downBumping){
animationState = "running";
} else if(downBumping){
animationState = "idle";
} else {
animationState = "jumping";
}
if(player.currentLabel != animationState){
player.gotoAndStop(animationState);
}
if (enemyList.length > 0)
{
for (var i:int = 0; i < enemyList.length; i++)
{
if (bulletList.length > 0)
{
for (var j:int = 0; j < bulletList.length; j++)
{
if ( enemyList.hitTestObject(bulletList
) ) {
trace("Bullet Hit Enemy");
pScore += 10.1;
scoreTxt.text=String(pScore);
enemyList.removeSelf();
bulletList
.removeSelf(); }
}
}
}
}
if (enemyList.length > 0){
for (var k:int = 0; k < enemyList.length; k++){
if (bumperList.length > 0){
for (var h:int = 0; h < bumperList.length; h++){
if ( enemyList
.hitTestObject(bumperList ) ){ enemyList
.changeDirection(); }
}
}
}
}
if (enemyList.length > 0){
for (var m:int = 0; m < enemyList.length; m++){
if ( enemyList
.hitTestObject(player) ){ trace("Player Hit Enemy");
scrollX = 0;
scrollY = 500;
lives -= 1;
lifeTxt.text=String(lives);
}
}
}
if (lives == 0){
gotoAndStop(3);
}
}
function nextLevel():void{
currentLevel++;
trace("Next Level: " + currentLevel);
gotoNextLevel();
addEnemiesToLevel();
if(currentLevel == 4){
gotoAndStop(4);
}
}
function gotoNextLevel():void{
back.other.gotoAndStop(currentLevel);
back.visuals.gotoAndStop(currentLevel);
back.collisions.gotoAndStop(currentLevel);
scrollX = 0;
scrollY = 500;
keyCollected = false;
back.other.doorKey.visible = true;
doorOpen = false;
back.other.lockedDoor.gotoAndStop(1);
}
function keyDownHandler(e:KeyboardEvent):void{
if(e.keyCode == Keyboard.LEFT){
leftPressed = true;
} else if(e.keyCode == Keyboard.RIGHT){
rightPressed = true;
} else if(e.keyCode == Keyboard.UP){
upPressed = true;
} else if(e.keyCode == Keyboard.DOWN){
downPressed = true;
if(doorOpen && player.hitTestObject(back.other.lockedDoor)){
nextLevel();
}
}
}
function keyUpHandler(e:KeyboardEvent):void{
if(e.keyCode == Keyboard.LEFT){
leftPressed = false;
} else if(e.keyCode == Keyboard.RIGHT){
rightPressed = false;
} else if(e.keyCode == Keyboard.UP){
upPressed = false;
} else if(e.keyCode == Keyboard.DOWN){
downPressed = false;
}
if(e.keyCode == Keyboard.SPACE){
fireBullet();
}
}
function fireBullet():void
{
var playerDirection:String;
if(player.scaleX < 0){
playerDirection = "left";
} else if(player.scaleX > 0){
playerDirection = "right";
}
var bullet:Bullet = new Bullet(player.x - scrollX, player.y - scrollY, playerDirection, xSpeed);
back.addChild(bullet);
bullet.addEventListener(Event.REMOVED, bulletRemoved);
bulletList.push(bullet);
}
function bulletRemoved(e:Event):void
{
e.currentTarget.removeEventListener(Event.REMOVED, bulletRemoved);
bulletList.splice(bulletList.indexOf(e.currentTarget), 1);
}
function addEnemy(xLocation:int, yLocation:int):void
{
var enemy:Enemy = new Enemy(xLocation, yLocation);
back.addChild(enemy);
enemy.addEventListener(Event.REMOVED, enemyRemoved);
enemyList.push(enemy);
}
function addBumper(xLocation:int, yLocation:int):void
{
var bumper:Bumper = new Bumper(xLocation, yLocation);
back.addChild(bumper);
bumper.visible = false;
bumperList.push(bumper);
}
function enemyRemoved(e:Event):void
{
e.currentTarget.removeEventListener(Event.REMOVED, enemyRemoved);
enemyList.splice(enemyList.indexOf(e.currentTarget), 1); //this removes 1 object from the enemyList, at the index of whatever object caused this function to activate
}
And the Bumper Class is:
package {
import flash.display.MovieClip;
import flash.events.Event;
public class Bumper extends MovieClip{
public function Bumper(xLocation:int, yLocation:int) {
// constructor code
x = xLocation;
y = yLocation;
addEventListener(Event.ENTER_FRAME, bumper);
}
public function bumper(e:Event):void{
//code here
}
}
}
Please help me, I don't really understand the error. I tried reading documentation on it but I just got confused.
you have a movieclip with class = Bumper on frame 5. that's the problem.
Copy link to clipboard
Copied
there's no problem with that code (with respect to the posted error).
to confirm, place a trace in your addBumper function that will probably show the posted code is not being used.
Copy link to clipboard
Copied
Well. I'm confused then.Because when I go from Frame 1 to 3 it gives me this (The entire error)
ArgumentError: Error #1063: Argument count mismatch on Bumper(). Expected 2, got 0.
at flash.display::MovieClip/gotoAndPlay()
at Sidescroller_fla::MainTimeline/beginGame()
beginGame isn't found anywhere..
gotoAndPlay is what I use when you click the New Game button on Frame 1
Edit:
Upon adding this trace:
trace("Being Used");
It output that text 8 times. 4 enemies, and 2 bumpers for each.
Copy link to clipboard
Copied
click file>publish settings>swf and tick "permit debugging". retest.
copy and paste the complete error message.
indicate the lines of code referenced in the error message.
Copy link to clipboard
Copied
Attempting to launch and connect to Player using URL C:\Users\watsonj\Documents\Adobe Flash\Sidescroller Part 13\Sidescroller.swf
[SWF] C:\Users\watsonj\Documents\Adobe Flash\Sidescroller Part 13\Sidescroller.swf - 76567 bytes after decompression
ArgumentError: Error #1063: Argument count mismatch on Bumper(). Expected 2, got 0.
at flash.display::MovieClip/gotoAndPlay()
at Sidescroller_fla::MainTimeline/beginGame()[Sidescroller_fla.MainTimeline::frame1:56]
Line 56 is GotoAndPlay(5);
- it changed because I was trying to get cookies to work.
Copy link to clipboard
Copied
you have a movieclip with class = Bumper on frame 5. that's the problem.
Copy link to clipboard
Copied
What's the solution?
Copy link to clipboard
Copied
1. don't use a movieclip with class = Bumper
2. don't use parameters in the Bumper class constructor
3 assign parameters in the class constructor default values.
Copy link to clipboard
Copied
I need the bumper to create wall objects for the Enemy's in game or else they just float off.
Copy link to clipboard
Copied
what's that have to do with 2 or 3?
Copy link to clipboard
Copied
I have absolutly no clue, I'm new to packaging and everything.
Usually I make everything in a single .fla file
Copy link to clipboard
Copied
there's no code shown by you that uses the two parameters passed in the constructor. so, it's not clear that's needed, at all.
but, if it is, try:
package {
import flash.display.MovieClip;
import flash.events.Event;
public class Bumper extends MovieClip{
public function Bumper(xLocation:int=0, yLocation:int=0) {
// constructor code
if(this.stage){
x=this.x;
y=this.y;
} else {
x = xLocation;
y = yLocation;
}
addEventListener(Event.ENTER_FRAME, bumper);
}
public function bumper(e:Event):void{
//code here
}
}
}
Copy link to clipboard
Copied
Thank you a lot. This actually solved like 5 other bugs I had
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now