This content has been marked as final. Show 3 replies
you are alwasys SETTING choice equal to ans. Instead, use the double equal operator:
choice == ans
This one STILL catches me sometimes.
Next, on the save a variable question, you can persist data to a Local Shared Object. Check the docs, this is pretty easy, post back if you have difficulty.
Third, ALL functions and instance-level (not declared in a function) variables should be explictily scoped. the main options are public, private, and there are a couple others.
Interesting you got that problem with the == vs =. The compiler provides a warning if you do this with anything but an assignment to an explicitly declared Boolean variable or parameter. Hence in your example I would expect two warnings: one on the line of your function declaration about parameter 'choice' having no type declaration, and another warning on the if() line saying "Assignment in conditional. Did you mean == instead of =?". My experience says "never ignore a warning" - if you have a problem and there's a compiler warning, your first assumption should be that it may be related. Interestingly, in this single case, failing to declare a type on the Choice parameter actually saves you from the assignment error because it causes a warning - if you actually declare the type of the choice parameter (and perhaps you did and just didn't transcribe it in your post), it provides no warnings at all.
That said - I have also been caught by it before. Though I'll say not nearly as often these days with smart compilers in AS and Java as the old days with C!
ahh.. the == makes sense now. i must have had somethig wrong when i originally tried the == instead of =, but it works now. thanks.
as for the shared object.. i'm looking into that now. this is all new to me so i'm trying to figure out how it is used.