I'm making a drag-and-drop game. On the MouseEvent.MOUSE_UP I have an if-statement like so:
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" is an earlier declared var of type Card(); and it's set in the MouseEvent.MOUSE_DOWN like so:
function fnDown(event:MouseEvent):void
{
clicked = event.currentTarget as Card;
clicked.bg.gotoAndStop("on");
clicked.startDrag();
addChild(clicked);
}
I thought that if I build my if-statement like this there wouldn't be an error if the card was dropped anywhere but on one of the three possible target cards. But I still get:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
tldr; I get an error if I drop my card outside one of the 3 possible targets.