I seem to have a bit of a problem with getting the collision detection working in harmony with the rest of my code. Basically i have an array that creates multiple instances of a movieclip named mcPlatformStandard with the following piece of code…
//this variable holds all of the platforms
var platformHolder:MovieClip = new MovieClip();
//adds the platform to stage
addChild(platformHolder);
function createLvlOne():void{
//now we must create the level
for(var i:int = 0;i<xStandardOneArray.length;i++){
//making a new standard platform
var platformStandard:mcPlatformStandard = new mcPlatformStandard();
//adding platformStandard to stage
platformHolder.addChild(platformStandard);
platformStandard.x=levelOneArray[0][0]*;
platformStandard.y=levelOneArray[0][1]*;
}
}
//running the createlvl funciton
createLvlOne();
This seems to work well enough. When i try and when i link the following code (which contains the hit test) with the main file, however, it just plain doesn’t work…
package{
import flash.display.MovieClip;
import flash.events.*;
public class mcPlatformStandard extends MovieClip {
var _root:Object;//this will symbolize the main timeline
public function mcPlatformStandard() {
addEventListener(Event.ADDED, standardJump);
}
private function standardJump(e:Event):void{
if(this.hitTestObject(_root.mcMain)){//if this touches the main character
_root.mainJumping = true;//make him jump
_root.jumpSpeed = _root.jumpSpeedLimit*-1;//reset the jumpSpeed
}
}
}
}
In the output tab it says
“TypeError: Error #1009: Cannot access a property or method of a null object reference.
at mcPlatformStandard/standardJump()
at flash.display::DisplayObjectContainer/addChild()
at MyGame_fla::MainTimeline/createLvlOne()
at MyGame_fla::MainTimeline/frame2()”
Please someone tell me what im missing. Im not that experienced with classes but i will try any advice im given.
Thanks in advance (and sorry for bad terminology)