actionscript 3 - Remove discovered cards -


i'm creating flash "memory" game, idea discover 2 equal cards. fine, need make when cards discovered deleted. stay shown.

when try: removechild(_card.currenttarget._type);

i receive error: c:\...\memorygame.as, line 202 1119: access of possibly undefined property currenttarget through reference static type card.

here part of code:

    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); 

could me?

edit:

when use: removechild(_firstcard)

i receive error: typeerror:

error #2007: parameter child must non-null. @ flash.display::displayobjectcontainer/removechild() @ memorygame/checkcards()[c:\users\rimante\desktop\gerase\gerase\memorygame.as:218]` 

when use: removechild(event.currenttarget);

i receive error:

c:\users\rimante\desktop\gerase\gerase\memorygame.as, line 217  1118: implicit coercion of value static type object possibly unrelated type flash.display:displayobject. 

try

 removechild(event.currenttarget displayobject)  removechild(_firstcard displayobject) 

the removal of _firstcard throws error because set var undefined. remove

 _firstcard = undefined; 

or move line below removechild-lines.

if want delay try:

function removecards(firstcard:displayobect, secondcard:displayobject):void{     removechild(firstcard);     removechild(secondcard); } 

and within event listener call

settimeout(removecards, 1000, _firstcard displayobject, event.currenttarget displayobject); 

and remove removechild lines


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -