你好我'我试图以两条线的形式制作两个collison墙,我已经给出了实例名称' colission1'和' colission2'我已经使用以下代码使汽车消失,并且当它们被汽车git时弹出游戏消息;
addEventListener(Event.ENTER_FRAME, hit1);
function hit1(e:Event):void {
if (car_mc.hitTestObject(colission2_mc))
{
gotoAndPlay(2);
gotoAndStop(2);
car_mc.visible = false;
stop();
}
else
{
car_mc.visible = true;
}
}
addEventListener(Event.ENTER_FRAME, hit2);
function hit2(e:Event):void {
if (car_mc.hitTestObject(colission1_mc))
{
gotoAndPlay(2);
gotoAndStop(2);
car_mc.visible = false;
stop();
}
else
{
car_mc.visible = true;
}
}
然后我收到此错误;
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at Gamev1_fla::MainTimeline/hit1()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at Gamev1_fla::MainTimeline/hit2()
答案 0 :(得分:0)
您将转到另一个框架,其中car_mc或colission2_mc不再存在,但由于您没有删除enterframe侦听器,因此它一直运行hit1并且您收到错误。删除enterframe侦听器。
答案 1 :(得分:0)
理想情况下,您可以在单个ENTER_FRAME事件上执行此操作,而不是创建两个event_frame事件。此外,当您可以通过以下方式之一摆脱错误:
理想情况下,代码应如何:
addEventListener(Event.ENTER_FRAME, checkHits);
function checkHits(e:Event):void {
if (car_mc.hitTestObject(colission2_mc))
{
removeEventListener(Event.ENTER_FRAME, checkHits);
gotoAndStop(2);
car_mc.visible = false;
stop();
}
else if (car_mc.hitTestObject(colission1_mc))
{
removeEventListener(Event.ENTER_FRAME, checkHits);
gotoAndStop(2);
car_mc.visible = false;
stop();
}
else
{
car_mc.visible = true;
}
}