我正在创建 Flash“记忆”游戏,想发现 2 张相等的卡片。一切都很好,只是我需要这样做,当发现卡片时,它们将被删除。现在它保持显示。
当我尝试:
removeChild(_card.currentTarget._type);
我收到错误:
C:\...\MemoryGame.as, Line 202 1119: Access of possibly undefined property currentTarget through a reference with static type Card.
以下是部分代码:
for(var l:Number = 0; l < 2; l++)
{
_card = new Card();
addChild(_card);
_snow = new Snow();
_card.setType(_snow);
_card.x = _cardX;
_card.y = _cardY;
_cardX += _card.width + 50;
_card.addEventListener(MouseEvent.CLICK, checkCards);
_cards.push(_card);
}
private function checkCards(event:MouseEvent):void
{
event.currentTarget.removeEventListener(MouseEvent.CLICK, checkCards);
if(_firstCard == undefined)
{
_firstCard = event.currentTarget;
}
else if(String(_firstCard._type) == String(event.currentTarget._type))
{
trace("Match");
_message = "Match";
message_txt.text = _message;
_firstCard = undefined;
_currentMatches ++;
removeChild(_card.currentTarget._type);
你可以帮帮我吗?
编辑:
当我使用:removeChild(_firstCard)
我收到错误:TypeError:
Error #2007: Parameter child must be non-null. at flash.display::DisplayObjectContainer/removeChild() at MemoryGame/checkCards()[C:\Users\Rimante\Desktop\gerase\gerase\MemoryGame.as:218]`
当我使用:removeChild(event.currentTarget);
我收到错误:
C:\Users\Rimante\Desktop\gerase\gerase\MemoryGame.as, Line 217 1118: Implicit coercion of a value with static type Object to a possibly unrelated type flash.display:DisplayObject.