Edit: I have now included a Player.as and a addchild
I've been trying to understand how to do this all day and again learned a lot in doing so. But I've come to a point that i need help.
I know I have to do this: create a Collisions var in the Back1 class.
Because the background called Back1 is the movieclip that contains the Collisions image
I found a good site or 2 that does a good job of explaining variables and classes but i still don't get how i should solve this problem
Research after variables and classes:
http://www.republicofcode.com/tutorials/flash/as3variables/
the above problem results in the folowing error but i believe it is caused by not creating a Collisions var in the Back1 class
ArgumentError: Error #1063: Argument count mismatch on Bumper(). expected: 2, value 0.
at flash.display::MovieClip/gotoAndStop() at DocumentClass/onRequestStart()DocumentClass.as:64] at flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at MenuScreen/onClickStart()MenuScreen.as:18]
package { import flash.display.MovieClip; import flash.events.*; import flash.events.KeyboardEvent; import flash.ui.Keyboard; import flash.geom.Point; import Bumper; //import Back1; public class Test extends MovieClip { public var leftBumping:Boolean = false; public var rightBumping:Boolean = false; public var upBumping:Boolean = false; public var downBumping:Boolean = false; public var leftBumpPoint:Point = new Point(-30,-55); public var rightBumpPoint:Point = new Point(30,-55); public var upBumpPoint:Point = new Point(0,-120); public var downBumpPoint:Point = new Point(0,0); public var scrollX:Number = 0; public var scrollY:Number = 500; public var xSpeed:Number = 0; public var ySpeed:Number = 0; public var speedConstant:Number = 4; public var frictionConstant:Number = 0.9; public var gravityConstant:Number = 1.8; public var jumpConstant:Number = -35; public var maxSpeedConstant:Number = 18; public var doubleJumpReady:Boolean = false; public var upReleasedInAir:Boolean = false; public var keyCollected:Boolean = false; public var doorOpen:Boolean = false; public var currentLevel:int = 1; public var animationState:String = "idle"; public var bulletList:Array = new Array(); public var enemyList:Array = new Array(); public var bumperList:Array = new Array(); public var back1:Back1; public var collisions:Collisions; //public var back1:Collisions = new Collisions ; public var player:Player; public function Test() { addEventListener(Event.ADDED_TO_STAGE, init); } public function init(e:Event):void { player = new Player(320, 360); back1 = new Back1(); collisions = new Collisions(); //back1.collisions = new Collisons(); addBumpersToLevel1(); } public function addBumpersToLevel1():void { addBumper(500, -115); addBumper(740, -115); } public function addPlayerTolevel1():void { addPlayer(320, 360); } public function loop(e:Event):void { trace("back1.collisions "+back1.collisions); trace("back1 "+back1); trace("collisions "+collisions); if (back1.collisions.hitTestPoint(player.x + leftBumpPoint.x,player.y + leftBumpPoint.y,true)) {
just in case i've added Bumper.as
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
}
}
}
Player.as
package {
import flash.display.MovieClip;
import flash.events.Event;
public class Player extends MovieClip {
public function Player(xLocation:int, yLocation:int) {
// constructor code
x = xLocation;
y = yLocation;
}
// public function removeSelf():void {
// trace("remove enemy");
// removeEventListener(Event.ENTER_FRAME, loop);
// this.parent.removeChild(this);
// }
}
}
the Back1.as file (note it's got to be instanced wrong)
package {
import flash.display.MovieClip;
public class Back1 extends MovieClip {
//public var collisions:Back1;
//what should i put here?
}
}