0
여기에 질문이 있습니다. 나는 우주 침략자 게임을하고있다. 오류 메시지가 표시됩니다.TypeError : 오류 # 2007 : 매개 변수 hitTestObject가 null이 아니어야합니다.
TypeError : Error # 2007 : 매개 변수 hitTestObject는 null이 아니어야합니다. flash.display : DisplayObject입니다/hitTestObject() 적/eFrame() 나는 당신의 사람이 나를 도울 수 있기를 바랍니다
에서 에서 flash.display : DisplayObject입니다/_hitTest에서 () . 대단히 감사합니다!
//This is the basic skeleton that all classes must have
package{
//we have to import certain display objects and events
import flash.display.MovieClip;
import flash.events.*;
//this just means that Enemy will act like a MovieClip
public class Enemy extends MovieClip{
//VARIABLES
//this will act as the root of the document
//so we can easily reference it within the class
private var _root:Object;
//how quickly the enemy will move
private var speed:int = 5;
//this function will run every time the Bullet is added
//to the stage
public function Enemy(){
//adding events to this class
//functions that will run only when the MC is added
addEventListener(Event.ADDED, beginClass);
//functions that will run on enter frame
addEventListener(Event.ENTER_FRAME, eFrame);
}
private function beginClass(event:Event):void{
_root = MovieClip(root);
}
private function eFrame(event:Event):void{
//moving the bullet up screen
y += speed;
//making the bullet be removed if it goes off stage
if(this.y > stage.stageHeight){
removeEventListener(Event.ENTER_FRAME, eFrame);
_root.removeChild(this);
}
//checking if it is touching any bullets
//we will have to run a for loop because there will be multiple bullets
for(var i:int = 0;i<_root.bulletContainer.numChildren;i++){
//numChildren is just the amount of movieclips within
//the bulletContainer.
//we define a variable that will be the bullet that we are currently
//hit testing.
var bulletTarget:MovieClip = _root.bulletContainer.getChildAt(i);
//now we hit test
if(hitTestObject(bulletTarget)){
//remove this from the stage if it touches a bullet
removeEventListener(Event.ENTER_FRAME, eFrame);
_root.removeChild(this);
//also remove the bullet and its listeners
_root.bulletContainer.removeChild(bulletTarget);
bulletTarget.removeListeners();
//up the score
_root.score += 5;
}
}
//hit testing with the user
if(hitTestObject(_root.mcMain)){
//losing the game
_root.gameOver = true;
_root.gotoAndStop('lose');
}
if(_root.gameOver){
removeEventListener(Event.ENTER_FRAME, eFrame);
this.parent.removeChild(this);
}
}
public function removeListeners():void{
this.removeEventListener(Event.ENTER_FRAME, eFrame);
}
}
}
문제를 해결하는 방법을 알고 있습니까? thankyou. – userNoIdea
글쎄, 내 관점에서 [mcMain]은 정의되지 않았다. 게다가 그 변수가 정의되지 않은 이유를 찾아야한다. – loxxy
기본 소스에 정의했습니다. – userNoIdea