This content has been marked as final. Show 5 replies
cardArray.length is probably undefined.
Thanks for replying to my question - much appreciated!
Unfortunately, I am still fighting the NaN - i put in trace statements to make sure that the cardArray.length was being tracked and I can see in the output panel as it is gradually being spliced down to nothing while the randArray is being filled. If cardArray.length was undefined wouldn't that result in randArray being empty?
At the end of the randomization process I do end up with randArray filled with numbers in a different order so I was able to "sucessfully" transfer them from the cardArray to the new randArray. And I can look at say randArray which shows, for example, 5 so it looks like I have everything I need except that if I try to do any math such as
trace(randArray +1) I get the dreaded NaN instead of 6.I
The cardArray contained numbers and math functions worked on the contents at the various indexed locations. After randomization, I end up with a new array with what should be the same contents (in a different order) and it looks right when I do a trace statement but... again any attempt to work math results in the NaN.
Any other suggestions?
Again thanks for taking the time out of your day to point towards a possible solution.
Geez Leslie, this was a stumper until I tried something that worked and then went to check in the splice method to see what it returns. Therein lies the problem... it returns an array, which makes sense, not the value you removed. So when you trace it at the end, you are tracing an array of arrays, each holding just one value. If you had used randArray[#] you would have gotten the numbers you were looking for.
Change it to:
randArray[ i ] = cardArray[randNumber];
var dontCare = cardArray.splice(randNumber, 1);
and your problems should be over.
It will work without the "var dontCare =", but I don't know where in the ethereal it ends up otherwise.
Thank you, Thank you, Thank you!!!!!
You just became my favourite super hero - this thing had me pulling my hair out.
And... after all the debugging and things I tried it not once occurred to me that the splice was the problem and to look at the documentation for it. Major blind spot!!!!
Again - thanks so much!
You're welcome.... if I were a super hero I would have spotted it right away with my amazing been there done that vision--but it took awhile instead. I have done this same routine quite a few times and probably did the hair pulling bit the first time around because after that it just became second nature to me to do it as I showed you, apparently forgetting why.