所以,基本上我在使用 hitTesting 时遇到了这个问题。在我完成的所有 AS3 中,我从来没有遇到过这个错误。我正在使用拖放,基本上你必须将垃圾拖到垃圾箱中。非常直截了当。这是搞砸的代码,给了我错误:
if(coin3.hitTestObject(wallet1)) {
coins +=1;
coin3.x -=7000;
}
所以这个错误真的很烦我,我需要修复它,它正在破坏我的游戏!我没有将对象分配给变量或数据类型,就这么简单。我该如何解决这个问题?我不知道什么是空!这是整个代码:
import flash.events.Event;
import flash.events.MouseEvent;
var coins:Number = 0;
var maxcoins:Number = 3;
coin2.addEventListener(MouseEvent.MOUSE_DOWN, coin2drag);
function coin2drag(e:MouseEvent)
{
coin2.startDrag();
}
stage.addEventListener(MouseEvent.MOUSE_UP, coin2undrag);
function coin2undrag(e:MouseEvent)
{
coin2.stopDrag();
}
coin3.addEventListener(MouseEvent.MOUSE_DOWN, coin3drag);
function coin3drag(e:MouseEvent)
{
coin3.startDrag();
}
stage.addEventListener(MouseEvent.MOUSE_UP, coin3undrag);
function coin3undrag(e:MouseEvent)
{
coin3.stopDrag();
}
coin4.addEventListener(MouseEvent.MOUSE_DOWN, coin4drag);
function coin4drag(e:MouseEvent)
{
coin4.startDrag();
}
stage.addEventListener(MouseEvent.MOUSE_UP, coin3undrag);
function coin4undrag(e:MouseEvent)
{
coin4.stopDrag();
}
coin2.addEventListener(Event.ENTER_FRAME, coin2hit);
function coin2hit(e:Event)
{
if (coin2.hitTestObject(wallet1))
{
coins += 1;
coin2.x += 700000;
}
if (coins == maxcoins)
{
gotoAndStop(54);
}
}
coin3.addEventListener(Event.ENTER_FRAME, coin3hit);
function coin3hit(e:Event)
{
if (coin3.hitTestObject(wallet1))
{
coins += 1;
coin3.x += 700000;
}
};
coin4.addEventListener(Event.ENTER_FRAME, coin4hit);
function coin4hit(e:Event)
{
if (coin4.hitTestObject(wallet1))
{
coins += 1;
coin4.x += 700000;
}
};