我收到一个错误,我似乎无法修复。我想我知道发生了什么,但我不确定是否能够修复它。我不断收到错误Actionscript 3.0,错误与hitTestObject
“类型错误:错误#2007:参数hitTestObject必须为非空
在flash.display使用::的DisplayObject/_hitTest()
在flash.display使用::的DisplayObject/hitTestObject()“
基本上我在我的游戏中发起攻击。它击中一个敌人,他被杀死的很好。但是,他有一个动画,他死了,需要几秒钟。看起来如果我在他的动画中发起了另一次攻击,我的攻击立即发出这个错误(在发生任何事情之前,就是这样)。一旦动画结束,一切都很好。此外,在我投入此动画之前,游戏正在100%正常工作。
这里是我的文档类
package com.classes
{
import flash.display.MovieClip;
import flash.display.Stage;
import flash.events.Event;
public class DocumentClass extends MovieClip
{
// we need to keep track of our enemies.
public static var enemyList1:Array = new Array();
// moved stickobject1 to a class variable.
private var stickobject1:Stickman2;
public function DocumentClass() : void
{
//removed the var stickobject1:Stickman2 because we declared it above.
var bg1:background1 = new background1();
stage.addChild(bg1);
stickobject1 = new Stickman2(stage);
stage.addChild(stickobject1);
stickobject1.x=50;
stickobject1.y=300;
//running a loop now.... so we can keep creating enemies randomly.
addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
}
//our loop function
private function loop(e:Event) : void
{
//run if condition is met.
if (Math.floor(Math.random() * 90) == 5)
{
//create our enemyObj1
var enemyObj1:Enemy1 = new Enemy1(stage, stickobject1);
//listen for enemyObj1 being removed from stage
enemyObj1.addEventListener(Event.REMOVED_FROM_STAGE, removeEnemyObj1, false, 0, true);
//add our enemyObj1 to the enemyList1
enemyList1.push(enemyObj1);
stage.addChild(enemyObj1);
}
}
private function removeEnemyObj1(e:Event)
{
enemyList1.splice(enemyList1.indexOf(e.currentTarget), 1);
}
}
}
这里是我的attack1类
package com.classes {
import flash.display.MovieClip;
import flash.display.Stage;
import com.senocular.utils.KeyObject;
import flash.ui.Keyboard;
import flash.events.Event;
public class attack1 extends MovieClip {
private var stageRef:Stage;
private var bulletSpeed:Number = 16;
public function attack1 (stageRef:Stage, x:Number, y:Number) : void
{
this.stageRef = stageRef;
this.x = x;
this.y = y;
addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
}
private function loop(e:Event) : void
{
//move bullet up
x += bulletSpeed;
if (x > stageRef.stageWidth)
removeSelf();
for (var i:int = 0; i < DocumentClass.enemyList1.length; i++)
{
if (hitTestObject(DocumentClass.enemyList1[i].hit))
{
trace("hitEnemy");
removeSelf();
DocumentClass.enemyList1[i].takeHit();
}
}
}
private function removeSelf() : void
{
removeEventListener(Event.ENTER_FRAME, loop);
if (stageRef.contains(this))
stageRef.removeChild(this);
}
}
}
不要认为你应该需要任何其他我的课要弄清楚是怎么回事,但让我知道如果你这样做! )非常感谢=)
谢谢!完美工作。这似乎也带来了另一个小小的缺陷,那就是当两个敌人密集在一起时,我的攻击会同时击中两个敌人。不完全确定为什么这有助于,但它不再做。所以双点指向u = p – spaderdabomb
不用客气。 “休息”;线是什么阻止了其他敌人的命中侦测。 – mfa