actionscript 3 - AS3 error 1061 trying to get collision -
" player.as, line 59 1061: call possibly undefined method hittestobject through reference static type class."
i new flash , trying make game, trying make player class in game can collide things, using square @ bottom of feet (not yet referenced in code) , movieclip called collisiontest
package { import flash.display.stage; import flash.display.movieclip; import flash.events.event; import keyobject; public class player extends movieclip { public var stageref:stage; public var key:keyobject; //add these 4 variables: public var leftpressed:boolean = false; //keeps track of whether left arrow key pressed public var rightpressed:boolean = false; //same, right key pressed public var uppressed:boolean = false; //...up key pressed public var downpressed:boolean = false; //...down key pressed private var gravity:number = 2; private var runspeed:number = 5; private var touchingground:boolean = false; public var vpressed:boolean = false; public function player(stageref:stage, x:int, y:int):void { this.stageref = stageref; this.x = x; this.y = y; key = new keyobject(stageref); addeventlistener(event.enter_frame, loop, false, 0, true); } public function loop(e:event):void { checkkeypresses(); //call "checkkeypresses()" every frame checkcollisions(); if(leftpressed) { x -= runspeed; }else if(rightpressed) { x += runspeed; } if(uppressed) { y -= runspeed; }else if(downpressed) { y += runspeed; } } public function checkcollisions():void { **(this line 59)** if(player.hittestobject(player.collisiontest)){ touchingground = true; trace("gounded"); } } public function checkkeypresses():void { // used http://www.dakmm.com/?p=272 reference keycode numbers each key if(key.isdown(37) || key.isdown(65)){ // if left arrow or pressed leftpressed = true; //trace("left pressed"); } else { leftpressed = false; } if(key.isdown(38) || key.isdown(87)){ // if arrow or w pressed uppressed = true; //trace("up pressed"); } else { uppressed = false; } if(key.isdown(39) || key.isdown(68)){ //if right arrow or d pressed rightpressed = true; //trace("right pressed"); } else { rightpressed = false; } if(key.isdown(40) || key.isdown(83)){ //if down arrow or s pressed downpressed = true; //trace("down pressed"); } else { downpressed = false; } } } }
function hittestobject isn't static function, should call object instance, same collisiontest.
so should be
this.hittestobject(collisiontest);//set collisiontest in player class
Comments
Post a Comment