| | | tlsilveus |  |
| Posted: Mon Jul 28, 2008 12:24 am Post subject: Case statement |  |
| |  | |
I am trying to make a word search program in which I have a specific set of words that I want the user to look for. I want to set up the grid according to the function below partially (its a 15x15 grid). My problem is that the case statement isn't working as I expect it to work. I am calling this function from within a loop that will enter with a unique row/col position each time, so each of these letters should be assigned only once. (I know this may not be the best way to do this, but since I'm new to programming in AS, I'm unsure of what might be best) Regardless... The results of these assignments is a grid of all "D"s which is the last letter in this embedded case statement. I stepped through case row = 1 and col = 1 and it assigned every single one of the letter statements and ended with D which is why my entire grid was filled with "D"s, but why did it do that? If case col = 1 why does it run a statement under case col=2 etc.?
function getButtonLabel(row,col):String {; var letter:String letter = 'Z' switch (row) { case 1: { switch (col) { case 1: {; letter = 'S' } case 2: {; letter = 'S' } } \\cut it short case 2: { switch (col) { case 1: {; letter = 'Y' } case 2: {; letter = 'P' } } \\ cut it short } } \\ cut it short return letter } |
|