Hey Folks,
I’m getting this error without any accompanying notes in the compiler output:
ArgumentError: Error #1063: Argument count mismatch on Ship$iinit(). Expected 2, got 0.
at flash.display::Sprite/flash.display:Sprite::constructChildren()
at flash.display::Sprite$iinit()
at flash.display::MovieClip$iinit()
at flash.display::Sprite/flash.display:Sprite::constructChildren()
at flash.display::Sprite$iinit()
at flash.display::MovieClip$iinit()
at Game$iinit()
I’ve been messing with the arguments I’ve put into the Game class in seemingly endless variations, but nothing gets rid of this error. I’m especially miffed because I am using essentially the same Ship code as the tutorial. Also, aside from the error pop-up, the game seems to run fine (the ship generates properly anyway, etc.).
The only time a Ship is created is in the initGame function in the Game class.
Here’s my Game.as class:
= = = = =
package
{
import flash.display.*
import flash.text.*
import flash.events.*
import flash.net.*
import flash.external.*
public class Game extends flash.display.MovieClip
{
//this static main property can be used to refer to this game object from anywhere easily using Game.main
static public var main;
//these values just store the width and height of the game
static public var WIDTH:int = 600;
static public var HEIGHT:int = 400;
//this property will just reference the hero ship
public var ship:Sprite;
//These are stats we can will track in our game
public var gameComplete:int;
public var kills:int;
public var points:int;
//there are two modes of play, normal and hard
public var difficultyMode:String; //“Normal” “Hard”
//we store these modes in static properties so we can refer to them easily
static public var NORMAL:String = “Normal”;
static public var HARD:String = “Hard”;
//This is the Document Class in our fla, and it will get constructed when we launch the swf
public function Game()
{
//set the static main property to this game object so we can always just use “Game.main” to refer to our game from other classes
main = this;
//hide some gui buttons
playNowButton.visible = false;
normalButton.visible = false;
hardButton.visible = false;
//fire up the keyboard input logic
Key.initialize(stage);
//add a loader to the game using these two event listeners
loaderInfo.addEventListener(Event.COMPLETE,completeListener);
}
public function completeListener(e:Event):void
{
playNowButton.visible = true;
//fire onPlay event when the user clicks the play button
playNowButton.addEventListener(MouseEvent.CLICK, onPlay);
}
//on play, show the normal and hard mode buttons
public function onPlay(e:MouseEvent)
{
//hide the play button
playNowButton.visible = false;
playNowButton.removeEventListener(MouseEvent.CLICK, onPlay);
//show the difficulty mode buttons
normalButton.visible = true;
hardButton.visible = true;
//add listeners for when these buttons are pressed
normalButton.addEventListener(MouseEvent.CLICK, onNormal);
hardButton.addEventListener(MouseEvent.CLICK, onHard);
}
//if normal mode button is pressed
public function onNormal(e:MouseEvent)
{
//set the mode in this class too
difficultyMode = NORMAL;
gotoAndStop(2);
gameOverMenu.visible = false;
//start game
initGame();
}
public function onHard(e:MouseEvent)
{
//IF we are using the kong api
//set the Kongregate HighScore API mode to HARD
//kongregate.scores.setMode(HARD);
//set the mode in this class too
difficultyMode = HARD;
gotoAndStop(2);
gameOverMenu.visible = false;
//start game
initGame();
}
//when a game is started
public function initGame()
{
//start the level manager that makes timers for power up intervals, enemy ship intervals, and miniboss intervals, etc…
LevelManager.init();
//resets all stats to zero for new game
initStats();
//make a new hero ship and position it in the middle of the stage
ship = new Ship(200, 300); //I also tried using WIDTH/2, HEIGHT/2 as in the tutorial, but this doesn’t work either!
//display the new hero ship
spriteClip.addChild(ship);
}
//After game over, this event will fire when the play again NORMAL mode button is pressed
public function onPlayAgainNormal(e:MouseEvent)
{
//remove the button event listeners
gameOverMenu.normalButton.removeEventListener(MouseEvent.CLICK, onPlayAgainNormal);
gameOverMenu.hardButton.removeEventListener(MouseEvent.CLICK, onPlayAgainHard);
// set this game’s mode
difficultyMode = NORMAL;
//hide the game over menu
gameOverMenu.visible = false;
// start a new game
initGame();
// reset the background
bg.reset();
bg2.reset();
}
//After game over, this event will fire when the play again HARD mode button is pressed
public function onPlayAgainHard(e:MouseEvent)
{
// remove the button event listeners
gameOverMenu.hardButton.removeEventListener(MouseEvent.CLICK, onPlayAgainHard);
gameOverMenu.normalButton.removeEventListener(MouseEvent.CLICK, onPlayAgainNormal);
// set this game’s mode
difficultyMode = HARD;
//show the game over menu
gameOverMenu.visible = false;
//start a new game
initGame();
//reset the background
bg.reset();
bg2.reset();
}
//this method resets the stats to zero for a new game
public function initStats()
{
scoreText.text = String(0);
kills = 0;
points = 0;
gameComplete = 0;
}
//update game stats, this method is called from throughout the classes whenever a stat needs to be updated
public function updateStat(stat:String, val:int)
{
//the name of the game stat is passed in along with the value to increment it by
Game.main[stat] += val;
scoreText.text = String(points);
}
//this mehtod id called when the game is over
public function gameOver()
{
//show the play again buttons
gameOverMenu.normalButton.addEventListener(MouseEvent.CLICK, onPlayAgainNormal);
gameOverMenu.hardButton.addEventListener(MouseEvent.CLICK, onPlayAgainHard);
var ac;
var h;
//stop the background
bg.disable();
bg2.disable();
//show the game over menu
gameOverMenu.visible = true;
//stop all the imers that level mamager started
LevelManager.main.stop();
//destroy all enemy ships
EnemyShip.killAll();
//MiniBoss.kill();
//MiniBossBullet.kill();
//Boss.kill();
//tally points
gameOverMenu.points.text = points;
//diplay point bounses
gameOverMenu.bonus.text ="x kills: " + kills + " (x 100)";
points = points + ((h * kills) + ac);
gameOverMenu.total.text = points;
scoreText.text = String(points);
}
}
}
= = = = =
Here’s my Ship.as class:
= = = = =
/*
This class controls the hero ship
*/package
{import flash.display.*
import flash.events.*
import flash.ui.*
import flash.filters.*
import flash.utils.Timer;
import flash.events.TimerEvent;public class Ship extends MovieClip
{
//the ship has this static property so it can be referenced from any class easily
static public var main;
//the ship’s fly speed
public var v:Number;
//buffers to keep ship from flying too far off screen
public var xBuffer:int;
public var yBuffer:int;
//a boolean property that makes sure the ship only fires when the space bar is pressed
public var spaceLocked:Boolean;//defines how long the ship will shake when it gets hit
public var shakeTimer:Timer;
//defines the current health of the ship
public var health:Number;
//defines the max health of the ship
public var maxHealth:Number;
//defines how violently the ship will shake
public var shakeStrength:int;
//holds an array of bitmap filters that can be applied to the ship
public var myFilters:Array;
//defines whether or not the ship currently has a shield
public var shield:Shield;
//the ship is created in the Game’s initGame() function
public function Ship(x_, y_)
{
//set the “main” property to equal this ship instance so any class can use “Ship.main” to refer to this ship
main = this;
//ship starts with no shield
shield = null;
//ship has 100 health max
maxHealth = 100;
//ship starts at max health
health = maxHealth;
//reset the health meter for the ship
Game.main.healthMeter.bar.scaleX = 1;
//hide the enemy health meter, until a miniboss is encountered
Game.main.enemyHealthMeter.bar.scaleX = 1;
Game.main.enemyHealthMeter.visible = false;
//decide on edge buffers so the ship cant leave screen
xBuffer = 50;
yBuffer = 25;
//position the ship based on x and y values passed in (middle of screen)
x = x_;
y = y_;
//decide on a speed for ship movement
v = 10;
//set the spaceLocked boolean to false, the spacebar is not being pressed
spaceLocked=false;
//add an ENTER_FRAME event so we can do some logic at frame rate
addEventListener(Event.ENTER_FRAME, enterFrame);
//add some listeners for key presses
Game.main.stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
Game.main.stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
//this just optimizes performance
cacheAsBitmap = true;
//let’s add a dropshadow filter to the ship for fun
var filter:BitmapFilter = new DropShadowFilter(5,45,0×000000,50,5,5);
myFilters = new Array();
myFilters.push(filter);
filters = myFilters;
}
//this method resets the ship
public function reset()
{
//rset the health to max health (100)
health = maxHealth;
//reset the health meter
Game.main.healthMeter.bar.scaleX = 1;
//reset and disable the enemy health meter
Game.main.enemyHealthMeter.bar.scaleX = 1;
Game.main.enemyHealthMeter.visible = false;
}
//event for key press
public function keyDownHandler(e:KeyboardEvent)
{
//if spacebar is pressed and is not currently, space bar fires bullet
if(e.keyCode == Keyboard.SPACE && spaceLocked==false)
{
//lock the spacebar until it is released in the keyUphandler, this allows only one bullet to fire at a time
spaceLocked=true;
//fire a bullet from this ship’s nose
var b = new Bullet(x+15, y+3);
//add the bullet to stage
Game.main.spriteClip.addChild(b);
//update the shots fired stat
Game.main.updateStat(“shots”,1);
}
}
//event for when a key is released
public function keyUpHandler(e:KeyboardEvent)
{
//when the spacebar is released
if(e.keyCode == Keyboard.SPACE)
{
//unlock it so another bullet can be fired when it’s pressed again
spaceLocked=false;
}
}
//do this at frame rate
public function enterFrame(e:Event)
{
move();
}
//at frame rate see if any of the arrows keys are being pressed
public function move()
{
//if the LEFT arrow key is being pressed and the ship isn’t too far left
if(Key.isDown(Keyboard.LEFT) && x > xBuffer)
{
//update its position, move it left
x -= v;
}
//if the RIGHT arrow key is being pressed and the ship isn’t too far right
else if(Key.isDown(Keyboard.RIGHT) && x < Game.WIDTH-xBuffer)
{
//update its position, move it right
x += v;
}
//if the UP arrow key is being pressed and the ship isn’t too far up
if(Key.isDown(Keyboard.UP) && y > yBuffer)
{
//update its position, move it up
y -= v;}
//if the DOWN arrow key is being pressed and the ship isn’t too far down
else if(Key.isDown(Keyboard.DOWN) && y < Game.HEIGHT-yBuffer)
{
//update its position, move it down
y += v;
}
}
//when the ship is killed
public function kill()
{
//create an explosion
var e = new Explosion(x, y);
//add th explosion to stage
Game.main.spriteClip.addChild(e);
//remove the ENTER_FRAME event
removeEventListener(Event.ENTER_FRAME, enterFrame);
//remove the keyboard listeners
Game.main.stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
Game.main.stage.removeEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
//kill the shake timer
shakeTimer.stop();
shakeTimer.removeEventListener(“timer”, shake);
shakeTimer.removeEventListener(TimerEvent.TIMER_COMPLETE, onShakeComplete);
//fire the game over logic in the game class
Game.main.gameOver();
//remove this ship from the stage
Game.main.spriteClip.removeChild(this);
Game.main.ship = null;
}
//when the ship takes damage
public function takeDamage(d_)
{
//play a damage sound
var s = new SoundTakeDamage();
s.play();
//in normal mode just subtract the damage
if(Game.main.difficultyMode == Game.NORMAL)
health -= d_;
//in hard mode, double the damage taken for everything
if(Game.main.difficultyMode == Game.HARD)
health -= 2 * d_;
//if the ship’s health reaches zero
if(health <= 0 )
{
//make sure healt is not less than zero
health = 0;
//kill it
kill();
//make sure the meter is set to zero
Game.main.healthMeter.bar.scaleX = 0;
}
else
{
//if the ship takes damage but is not destroyed, create an explosion
var e = new SmallExplosion(x, y);
//add that explosion to the stage
Game.main.spriteClip.addChild(e);
//if the ship is not currently shaking, begin a shake cycle
if(rotation == 0)
initShake();
//update the ship’s health meter
Game.main.healthMeter.bar.scaleX = (health/maxHealth);
}
}
//shaking ship logic
public function initShake()
{
//set shake strength
shakeStrength = 5;
//create a timer for the shake
shakeTimer = new Timer(50, 10);
shakeTimer.addEventListener(“timer”, shake);
shakeTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onShakeComplete);
shakeTimer.start();
}
//this will get fired every 50 millisecs for ten cycles by the shakeTimer
public function shake(e:TimerEvent)
{
//rotate the ship by the shakeStrength value
rotation += shakeStrength;
//then reverse the direction of the shake whe it reaches a threshold
if(Math.abs(rotation) >= 5)
{
shakeStrength *= -1;
}
}
//after ten ticks of the shakeTimer, kill the timer, and reset the ship’s rotation to 0
public function onShakeComplete(e:TimerEvent)
{
rotation = 0;
shakeTimer.removeEventListener(“timer”, shake);
shakeTimer.removeEventListener(TimerEvent.TIMER_COMPLETE, onShakeComplete);
}
}}
= = = = =
Any thoughts appreciated! Thanks! Also, feel free to let me know if there are other classes I should be posting, although editing the “ship = new Ship(200, 300);” line in Game.as seems to be the crux of the issue.
- InLiquidWonder