Skip to main content
FlashTapper
Inspiring
October 21, 2009
Answered

if else statement does not work...worked in AS2??

  • October 21, 2009
  • 1 reply
  • 1232 views

Hi there,

have a very common function i use in educational quizes that self rate the user depending on their score (resulting from answering multiple choice questions). So I have set up a variable called score no trouble...but when i implement my trust "if else" heuristic from AS2...i get all these errors and my flash file does not work.

Is there a better way to code this that I am not aware of ???

stop();

if (score <= 5){
endMsg.gotoAndStop("score1");
} else if (score > 6 and score <= 11){
endMsg.gotoAndStop("score2");
} else {
endMsg.gotoAndStop("score3");
}

feedback movie clip called "endMsg" - depending on function, navigates user to label that provides feedback.

Any help would be awesome...coz this function used to work!!!!! It doesn't even work in Flash CS4 when i retrograde the actionScript panel to version 2 for testing!!!

This topic has been closed for replies.
Correct answer Ned Murphy

I missed it... try using

} else if (score >= 6 && score <= 11){

I know they used to support using words for and/or, but never made a practice of it, so I can't say if they don't support it in AS3.  Also, as long as there won't be a score of 5.5 you should be okay.

1 reply

Ned Murphy
Brainiac
October 22, 2009

As is, there is nothing determinably wrong with that code, except that as written, a score of >5 and <=6 will bring you to the score3 frame.  If you show details of the errors you say you are getting it will be easier to determine what might be wrong.

FlashTapper
Inspiring
October 22, 2009

Thanks Ned,

I see your point about the code - t'was an oversight. Here it is revised:

if (score <= 5){
endMsg.gotoAndStop("score1");
} else if (score >= 6 and score <= 11){
endMsg.gotoAndStop("score2");
} else {
endMsg.gotoAndStop("score3");
}

And this is the error message I get (Have noticed that debugging/testing is a lot more strict with flash these days...a non fatal error will make the entire swf collapse!)

I hope this image is visible......If not...here it is attached

Ned Murphy
Ned MurphyCorrect answer
Brainiac
October 22, 2009

I missed it... try using

} else if (score >= 6 && score <= 11){

I know they used to support using words for and/or, but never made a practice of it, so I can't say if they don't support it in AS3.  Also, as long as there won't be a score of 5.5 you should be okay.