Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Explorer ,
Oct 21, 2009 Oct 21, 2009

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!!!

TOPICS
ActionScript
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Oct 21, 2009 Oct 21, 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.

Translate
LEGEND ,
Oct 21, 2009 Oct 21, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 21, 2009 Oct 21, 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!)

flashErrorMsg.jpg

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 21, 2009 Oct 21, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 21, 2009 Oct 21, 2009

Thanks again.

I feel quite dim. I have encountered this problem before and solved it doing the same thing.

Amazing how much you can forget!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 21, 2009 Oct 21, 2009

You're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 21, 2009 Oct 21, 2009
LATEST

and as Ned said, I still think you should double check your "numbers". Maybe it's better to use something like this:

if (score <= 5)...

else if (score > 5 and score <= 11)...


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines