The following piece of the as3 code is written for a card game, and I am curious, why I get Error #1010?
var backHands:Array = new Array();
var numberOfPlayingCards = 0;
function initBackHands(){
var i:int;
var j:int;
for(j=1;j<4;j++){
var newBacks:Array = new Array();
for(i=0;i<13;i++){
newBacks[i] = new CBack();
addChild(newBacks[i]);
}
backHands[j-1] = newBacks;
}
}
function removeBack(p:int){
try{
if(position[p]>0){
var index:int = (numberOfPlayingCards/4);
index = 12- index;
if(contains(backHands[position[p] - 1][index])){
removeChild(backHands[position[p] - 1][index]);
}
}
}catch(error:Error){
trace("playCard= NOPC: "+ numberOfPlayingCards +
" index: " + index +
" position: " + (position[p] - 1) +
" err: "+ error);
}
numberOfPlayingCards ++;
}
and this is the error log:
playCard= NOPC: 0 index: 12 position: 1 err: TypeError: Error #1010
playCard= NOPC: 1 index: 12 position: 0 err: TypeError: Error #1010
playCard= NOPC: 1 index: 12 position: 2 err: TypeError: Error #1010
playCard= NOPC: 2 index: 12 position: 0 err: TypeError: Error #1010
playCard= NOPC: 2 index: 12 position: 1 err: TypeError: Error #1010
playCard= NOPC: 3 index: 12 position: 2 err: TypeError: Error #1010
playCard= NOPC: 4 index: 11 position: 2 err: TypeError: Error #1010
playCard= NOPC: 5 index: 11 position: 1 err: TypeError: Error #1010
playCard= NOPC: 6 index: 11 position: 0 err: TypeError: Error #1010
playCard= NOPC: 8 index: 10 position: 0 err: TypeError: Error #1010
playCard= NOPC: 10 index: 10 position: 2 err: TypeError: Error #1010
playCard= NOPC: 11 index: 10 position: 1 err: TypeError: Error #1010
playCard= NOPC: 12 index: 9 position: 0 err: TypeError: Error #1010
The question is which line makes the error and why the NOPC does not increase regularly while we call removeBack function for each turn.
Please note that p is an integer between 0 and 3, and position is an array of integer of size 4 containing the position of each player(0,1, 2 or 3)