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

Checking Multiple Similar Or's in an if statement. [AS2]

New Here ,
Aug 16, 2013 Aug 16, 2013

Hello, I know this is probably a very obvious question, but I'm new to flash.

Can I do something like,

if (jellyfish == 3, 74, 95, || 1006) {

//Do Stuff

}

Or would I have to do:

if (jellyfish == 3 || jellyfish == 74 || jellyfish == 95 || jellyfish == 1006) {

//Do Stuff

}

Let me know if there is something closer to the first one, or if I'm going to have to have pages within one if statement.

Thanks,

Christopher

TOPICS
ActionScript
627
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

Community Expert , Aug 16, 2013 Aug 16, 2013

you must do the latter, but if it's worthwhile you can use a for-loop:

var a:Array=[3,74,95,1006];

for(var i:Number=0;i<a.length;i++){

if(jellyfish==a){

//do stuff

break;

}

}

Translate
Community Expert ,
Aug 16, 2013 Aug 16, 2013

you must do the latter, but if it's worthwhile you can use a for-loop:

var a:Array=[3,74,95,1006];

for(var i:Number=0;i<a.length;i++){

if(jellyfish==a){

//do stuff

break;

}

}

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
New Here ,
Aug 16, 2013 Aug 16, 2013

Thank you so much!
This is exactly what I needed!

You were missing a parenthisis, but besides for that, it works beautifully and looks a lot more visually appealing!

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
Community Expert ,
Aug 16, 2013 Aug 16, 2013
LATEST

you're welcome.

(and i corrected that paranthesis in case someone else copies that code.)

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 ,
Aug 16, 2013 Aug 16, 2013

The second is the correct way to specify multiple conditions

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
New Here ,
Aug 16, 2013 Aug 16, 2013

I know it is correct, but I was wondering if there was a simpler way.

Thanks for the help, though.

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