Issue with 'MyArray.splice'?
I have the following code in my ActrionScript 3.0 class:
if(RandTarget == true){
for(b = 0; b < totalHits; b++){
tempArray = tempArrayB.slice(0);
hitsPerTarget[tempArray.splice(Math.floor(Math.random() * tempArray.length), 1)] += 1;
}
}
This code is intended to set tempArray equal to tempArrayB, then add 1 to a specific spot on the hitsPerTarget array, which is determined randomly based on which number is spliced out of tempArray.
Using Trace, it appears that two elements are deleted from the hitsPerTarget array during each cycle of the for loop, instead of just one. However, if I change the "+= 1" part to just "= 1", it goes back to just deleting one element like it's supposed to. Why is this, and how can I fix it? I need this loop to add 1 to the chosen spot on the array for each cycle of the loop, and splice out no more than 1 one the elements in the array with each cycle.