Hi,
I’m making a little card game and load cards as sprite inside of an array. I add these array to the stage (addChild). What I would like to do is that when one card goes on a certain area, it is deleted from the array. I have figured out everything except how to delete only one element from the array while keeping the rest.
Here are the two problematic chunks of code:
private function loadDeck(evt:LoadedDeck):void {
theArray = evt.deckLoad;
for (var i:int = 0 ; i < theArray.length; i++) {
cardDeck* = new SingleCard(theArray*);
deckContainer.addChild(cardDeck*);
}
}
Above creates an instance of the SingleCard class for each cardDeck.
for (var i:int = 0; i < cardDeck.length; i++){
if (cardDeck* == e.target){
var numDel:Number = i;
}
}
trace("deleting card " + numDel + ", card deck was " + cardDeck.length);
[COLOR=Red]cardDeck.splice(numDel,numDel);[/COLOR]
trace("card deck is now " + cardDeck.length);
This chunk of code has unexpected results, I just tried to delete cardDeck[10] only and here is what is traced:
deleting card 10, card deck was 50
card deck is now 40
What I would expect is the card deck to now be 49… not just 40.
Thanks for your help,
Didi