basically my issue is i got my main class..which has a variable which is the object holding my levels. but when i try to add the child to the stage i get an error...i have never had this error before and i am very confused. The error i get is this
ArgumentError: Error #1063: Argument count mismatch on Levels/spawn(). Expected 0, got 1. at flash.display::DisplayObjectContainer/addChild() at Main()
here is my main class:
package {
import flash.display.MovieClip;
public class Main extends MovieClip {
public static var game:Levels = new Levels();
public function Main() {
game = new Levels();
addChild(game); //this triggers my error
game.y = 352;
}
}
}
here my is my levels class
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.KeyboardEvent;
public class Levels extends MovieClip
{
var platforms:Array = new Array();
var gravity:Number = 0;
var rPress:Boolean = false;
var lPress:Boolean = false;
var falling:Boolean = false;
var jumping:Boolean = false;
var velX:Number = 0;
var velY:Number = 0;
var a:int = 0;
public function Levels()
{
addEventListener(Event.ADDED_TO_STAGE, spawn);
}
function spawn()
{
removeEventListener(Event.ADDED_TO_STAGE, spawn);
getMap();
this.stage.addEventListener(KeyboardEvent.KEY_DOWN, kPress);
this.stage.addEventListener(KeyboardEvent.KEY_UP, kReleased);
this.addEventListener(Event.ENTER_FRAME, loop);
}
function getMap()
{
platforms.pop();
for (var a:int = 0; a < numChildren; a ++)
{
if (getChildAt(a) is Terrain)
{
platforms.push(getChildAt(a).getRect(this));
}
}
}
function kPress(event:KeyboardEvent)
{
if (event.keyCode == 65)
{
lPress = true;
}
if (event.keyCode == 68)
{
rPress = true;
}
if (event.keyCode == 32)
{
if (jumping == false)
{
gravity = -25;
jumping = true;
}
}
}
function kReleased(event:KeyboardEvent)
{
if (event.keyCode == 65)
{
lPress = false;
}
if (event.keyCode == 68)
{
rPress = false;
}
}
function loop(event:Event)
{
velX = 0;
if (rPress == true)
{
velX = 7;
}
if (lPress == true)
{
velX = -7;
}
velY = gravity;
_player.y += velY;
gravity += 2;
for (a = 0; a < platforms.length; a ++)
{
if (_player.getRect(this).intersects(platforms[a]))
{
if (velY > 0)
{
jumping = false;
_player.y = platforms[a].top - _player.height;
gravity = 0;
}
else if (velY < 0)
{
_player.y = platforms[a].bottom;
gravity = 0;
}
}
}
_player.x += velX;
if (rPress == true)
{
if (_player.x + _player.width / 2 > 336 + x * -1 && x + width > 640)
{
x -= velX;
}
}
else
{
if (_player.x + _player.width / 2 > 304 + x * -1 && x < 0)
{
x -= velX;
}
}
for (a = 0; a < platforms.length; a ++)
{
if (_player.getRect(this).intersects(platforms[a]))
{
if (velX == 7)
{
_player.x = platforms[a].x - _player.width;
x += velX;
}
if (velX == -7)
{
_player.x=platforms[a].x+platforms[a].width;
x += velX;
}
}
}
}
}
}