【发布时间】:2012-05-29 08:04:42
【问题描述】:
我正在制作一个拖放游戏。 在 MouseEvent.MOUSE_UP 我有一个这样的 if 语句:
function fnUp(event:MouseEvent):void
{
clicked.stopDrag();
if (clicked.dropTarget.parent.parent.name == clicked.currentLabel)
{
var dropped:Card = clicked.dropTarget.parent.parent as Card;
dropped.gotoAndStop(dropped.name);
dropped.bg.gotoAndStop("done");
removeChild(clicked);
}
else
{
clicked.x = clicked.sx;
clicked.y = clicked.sy;
clicked.bg.gotoAndStop("off");
}
clicked = null;
}
"clicked" 是较早声明的 Card() 类型的 var;它在 MouseEvent.MOUSE_DOWN 中设置如下:
function fnDown(event:MouseEvent):void
{
clicked = event.currentTarget as Card;
clicked.bg.gotoAndStop("on");
clicked.startDrag();
addChild(clicked);
}
我认为如果我像这样构建我的 if 语句,那么如果卡被丢弃在除了三个可能的目标卡之一之外的任何地方都不会出错。但我仍然得到:
TypeError:错误 #1009:无法访问空对象引用的属性或方法。
tldr;如果我将卡放在 3 个可能目标之一之外,我会收到错误消息。
【问题讨论】:
标签: actionscript-3 drag-and-drop flash-cs5