Alrighty-- Another challenge! I already wrote below about my fun with isNaN during this challenge. But let me try to document what I did for the challenge itself. Won't be too long...
Staying in the GameOverScreen.as file, I added the following to the constructor. (I called my array bestScoreArray) I wanted to check if the array was undefined or empty, and if so, create it.
- if( isNaN(sharedObject.data.bestScoreArray) )
- {
- }
Then, I figured I'd plug information when the final score was set. So down in the setFinalScre function:
- else if( scoreValue > sharedObject.data.bestScore )
- {
- // sharedObject.data.bestScore = scoreValue;
- sharedObject.data.bestScoreArray = [scoreValue, sharedObject.data.totalGames, "Test"];
- }
I'm grabbing three pieces of information and sticking it in an array -- score, total number of games played when that score was reached, and an arbitrary string of text just to test.
Ok, now I need to make sure it's working, so I threw this down below in the same 'setFinalScore' function. It will loop through the array and 'trace' every item to the output window.
- {
- trace( i, sharedObject.data.bestScoreArray[i] );
- }
Now run it.
D'oh! Didn't work... why not? Looking back through my code I realized this was wrong:
- if( isNaN( sharedObject.data.bestScoreArray ) )
Can you spot why? Because we're creating an array... so it's NEVER going to be a "number" (isNaN checks if something is 'not a number')
So, change that to this, and try again:
- if( sharedObject.data.bestScoreArray == null )
- {
- }
Voila! Should work now. If you have any problems, let me know.
No comments:
Post a Comment